1

I'm trying to create a rule (using the Rules module 8.x-3.x-dev) to send an email when someone creates content that is of the type Announcement or Article, but I can't seem to get the event to trigger properly. It's sending an email for every node that is created. Can anyone help with the proper method of setting the content type? My rule is as follows:

Event: After saving new content (rules_entity_insert:node)

Condition: Node is of type

Node Value: @node.node_route_context:node

Content Type Value: Announcement, Article

  • 1
    Are you familiar with this? – Pierre.Vriens Dec 8 '17 at 20:29
  • I've looked through that, but I found the documentation needlessly complex and haven't been able to find a simple example of what I need to do. – Lisa Huffman Dec 11 '17 at 16:07
  • I gave up trying to figure out the rules module and used this one instead for this purpose: drupal.org/project/admin_content_notification – Lisa Huffman Dec 12 '17 at 18:21
  • Merci for the extra comment. Good for you you found, at least for now (until rules for D8 is stable enough), some alternative. I suggest you rework your last comment into an actual answer (including a relevant quote from that module's project page). If you want, let me know if you want me to post an answer like that instead, ok? – Pierre.Vriens Dec 12 '17 at 18:41
2

I'm trying to create a rule (using the Rules module 8.x-3.x-dev) to send an email when someone creates content that is of the type Announcement or Article

To my knowledge, the current answer to this question is a no go: You can't do that yet with the most recent Drupal 8 version of the Rules module.

Refer to #d8rules status update November 2017 to get a better understanding of the current status of Rules for D8. Here are some quotes from it:

  • ... Fago can’t dedicate time required to develop the module further. What Rules is really missing at the moment is development capacity to help finish the last milestone.

  • ... Even if we got more funding today, fago the current principal maintainer of the Rules module wouldn’t have enough capacity to do the work himself.

One never realizes what has been done, only what remains to be done ... So start here if you wonder how to contribute.

Plan B

While waiting for Rules to become more mature, you can use the Admin Content Notification module as a temporary alternative (which does have an official D8 release already). Some details about it (from its project page):

... can be used for receive email notification when a new content of any content type will be created on your site. Although one can use rules for the same functionality but it's not good to use rules only for notification as it is a huge module, so we can use this module for small websites.

The "...Although one can use rules for the same functionality ..." part of this clearly does not apply to the D8 version of Rules (yet).

0

My experience is that this task is easily accomplished in D8 Rules, and has been working since at least November 2017 when I first started using D8 Rules.

A complete working example of using the "Node is of type" condition to execute an action when content of a specific type is updated was presented in the Rules issue queue last year, see https://www.drupal.org/project/rules/issues/2998793

Here's a slightly modified version of that answer, customized for your situation. This example shows a system warning message instead of sending an e-mail, because a system message is much easier to debug with. This Rule assumes your content type machine names are "announcement" and "article". If you import this Rule into your site, you should see the system warning displayed when a new "announcement" or "article" is created, but not when any other type of content is created. I have tested this on my site and it works.

langcode: en
status: true
dependencies: {  }
id: new_announcement_or_article
label: 'New Announcement or Article'
events:
  -
    event_name: 'rules_entity_insert:node'
description: ''
tags: {  }
config_version: '3'
expression:
  id: rules_rule
  uuid: 61868ee0-544e-4d88-92c3-d56f4a1d1c48
  conditions:
    id: rules_and
    uuid: 32d77b80-a17d-4c73-91a0-c9badcb79a4d
    conditions:
      -
        id: rules_condition
        uuid: 641c4be2-61f6-48e9-919d-190982358fe1
        context_values:
          types:
            - announcement
            - article
        context_mapping:
          node: node
        context_processors:
          types:
            rules_tokens: {  }
        provides_mapping: {  }
        condition_id: rules_node_is_of_type
        negate: false
  actions:
    id: rules_action_set
    uuid: 2ab1d627-4ecd-4b4c-9bf0-ad2730fbda14
    actions:
      -
        id: rules_action
        uuid: 88ed24cf-ef02-45bf-a977-96d8069b750e
        context_values:
          message: 'New {{ node.type }} was created'
          type: warning
          repeat: true
        context_mapping: {  }
        context_processors:
          message:
            rules_tokens: {  }
          type:
            rules_tokens: {  }
          repeat:
            rules_tokens: {  }
        provides_mapping: {  }
        action_id: rules_system_message

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.