2

I'm trying to figure out how to make the following work: Sending notification based on flagged node being linked via entity reference.

I have a 'News' content type and a 'Band' content type, that has a flag called 'fan'. When somebody becomes a fan, I want them to receive a notification via the Message module whenever I link the band to the content type 'News' with the News article I just created.

The content-type setup is as follows:

  • Node type 'News' has field: Entity reference to content type 'Band'

  • The Band content type has a flag called 'fan'

  • The Message type is called "user notification center" and has a field named field_mnc_recipients, which is an reference to a user(unlimited values)

How I want it to work:

  • when a user flags the 'band' and a new article is referenced to the band, I want to notify them with the Message module,
  • to make it work, I need to get the user from the flag for that band and insert it into the message field field_mnc_recipients.

I created a Rules Component as follows:

{ "rules_message_tes3" : {
"LABEL" : "message tes3",
"PLUGIN" : "rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules" ],
"USES VARIABLES" : {
  "referencing_node" : { "label" : "referencing_node", "type" : "node" },
  "referenced_node" : { "label" : "referenced_node", "type" : "message" }
},
"IF" : [
  { "node_is_of_type" : {
      "node" : [ "referencing-node" ],
      "type" : { "value" : { "bands" : "bands" } }
    }
  },
  { "entity_is_of_type" : { "entity" : [ "referenced-node" ], "type" : "message" } },
  { "entity_has_field" : { "entity" : [ "referenced-node" ], "field" : "field_mnc_recipients" } }
],
"DO" : [
  { "LOOP" : {
      "USING" : { "list" : [ "referencing-node:flag-fan-user" ] },
      "ITEM" : { "list_item" : "Current list item" },
      "DO" : [
        { "data_set" : {
            "data" : [ "referenced-node:field-mnc-recipients" ],
            "value" : [ "referencing-node:flag-fan-user" ]
          }
        },
        { "entity_create" : {
            "USING" : {
              "type" : "message",
              "param_type" : "user_notification_center",
              "param_user" : [ "site:current-user" ]
            },
            "PROVIDE" : { "entity_created" : { "entity_created" : "Created entity" } }
          }
        }
      ]
    }
  }
]

} }

And now I got stuck, I based the component on "Sending a message to users of a flagged node when it is referenced" which is close to what I want.

  • 1
    great question, too bad I don't have time to tackle this one, but seems doable. – No Sssweat May 12 '16 at 9:28
  • @NoSssweat still no time? I'm curious about what you were thinking "back then" ... – Pierre.Vriens Jun 21 '18 at 17:57
0

It works, after days and days it finaly works! I used this as a base line for my research: Sending a message to users of a flagged node when it is referenced

Instead of sending an e-mail within the loop, i create a new entity(action), in this case the message notification. After that i fill(set data) in the entity-created:field-mnc-recipients field with the flagging users. This is how it works :)

  • Please add an export of your rule in this answer to elaborate on how exactly you did this. And consider marking your own answer as "accepted" also (so that the question no longer appears as "unanswered" ...). – Pierre.Vriens Jun 21 '18 at 17:59

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.