0

I have installed a notification system and I want to create notifications with Rules when a project content is updated to waiting for approval status.

The rule looks like this:

uuid: 3165768f-15f5-4c35-a7e6-3f862b526f10
langcode: en
status: true
dependencies: {  }
id: project_updated
label: 'Project updated'
events:
  -
    event_name: 'rules_entity_update:node--project'
description: ''
tags: {  }
config_version: '3'
expression:
  id: rules_rule
  uuid: 4cead148-c63e-409d-a3e1-f9042c993fb6
  weight: 0
  conditions:
    id: rules_and
    uuid: b6e39609-9972-4805-af43-f2bdc66dc10b
    weight: 0
    conditions:
      -
    id: rules_condition
    uuid: 6d3b93ac-10ad-4b21-bbfd-1971c1aa44cc
    weight: 0
    context_values:
      operation: '=='
      value: waiting_for_approval
    context_mapping:
      data: node.moderation_state.value
    context_processors:
      operation:
        rules_tokens: {  }
      value:
        rules_tokens: {  }
    provides_mapping: {  }
    condition_id: rules_data_comparison
    negate: false
  actions:
    id: rules_action_set
    uuid: 39c0aaa8-f216-4255-a87b-484e94e075fc
    weight: 0
    actions:
      -
    id: rules_action
    uuid: 543fe5c3-83d0-4e46-932c-a197747868fb
    weight: 0
    context_values:
      token: '[current-date:raw]'
      token_entity: ''
    context_mapping: {  }
    context_processors:
      token:
        rules_tokens: {  }
      token_entity:
        rules_tokens: {  }
    provides_mapping:
      token_value: unix_time
    action_id: rules_token_get_token_value
      -
    id: rules_action
    uuid: 92aeaa68-c475-4ae7-97aa-2f74d72b89ff
    weight: 0
    context_values:
      user_id:
        - '1'
      provider_id: project
      notification_type: waiting_for_approval
      created: '{{ unix_time }}'
      title: 'New project waiting for approval: {{ node.title }}'
      priority: '3'
    context_mapping: {  }
    context_processors:
      user_id:
        rules_tokens: {  }
      provider_id:
        rules_tokens: {  }
      notification_type:
        rules_tokens: {  }
      created:
        rules_tokens: {  }
      title:
        rules_tokens: {  }
      priority:
        rules_tokens: {  }
    provides_mapping: {  }
    action_id: 'rules_entity_create:notification'

It's getting triggered and it's actually being executed the reactions (actions) also. However it does not create the entity, and I don't receive any error in the Recent log messages. With a little xdebug I've found that the tokens are replaced.
unix_time to a UNIX timestamp
node.title to the saved node title.

However, for some reason, the notification entity is not being created. How can I create an entity with rules if not like this?

1

Most likely you just need to add a "Save entity" action. Entities that are part of the context (in this case the project node) are automatically saved, but any entities you create during the rule may need to be explicitly saved.

1
  • You are correct, it does the trick. But I start realising that maybe my approach is wrong with that module, but I will see that later on. :D Nov 9 '21 at 20:19

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.