- Issue created by @rami.sedhom
- Status changed to Needs review
about 1 year ago 12:09am 8 September 2023 - last update
about 1 year ago 46 pass - π¬π§United Kingdom Janner
I'm looking to do the same as the OP, so was wondering if anyone has been successful in creating an ECA model that works with the Flag module to create a comment notification system?
Thanks for any pointers.
- π©πͺGermany drupalbubb
For easy use cases have a look at the message stack.
- π¬π§United Kingdom Janner
@DrupalBub
I'm actually wanting to migrate away from the Message Stack, which is what I currently use on the site I maintain. This is partly because it's overkill for my needs, but more importantly because it requires technical knowledge that I simply don't have.
The only reason I was able to get it working at all was thanks to a very detailed guide someone posted in the Message Subscribe issue queue. However, I'm concerned that changes in Drupal core or the Message Stack itself could break my notification system at any time. As someone without developer expertise, troubleshooting those kinds of issues in a timely manner would be extremely challenging.
My goal is to find a notification solution that better fits my limited technical skills and the basic requirements of my site. I'd like something simple and lightweight. A combination of the Flag and Rules module did this in the past. The ECA module has proved to be a great replacement for Rules in other areas, so I am hopeful that it can also be used in conjunction with Flag to create a comment notification system.
- π¨π·Costa Rica calebyoder
Hi there!
This was a bit complicated, but I think I got it working..
Using Flag module to allow people to "follow" content, and the ECA module to send email notifications when there's a new comment on followed content/node or when the content/node itself is updated.
(Note: I'm dealing with a Spanish site, so forgive me if some of my terms aren't always correct in English.)
#1 Setup the flag system on the content type you're needing it on.
#2 Create a view that shows Content not Flags (See screenshot)
In the view settings under Format, I set it to use Unformatted list. Under the configuration for that you can uncheck the option for adding classes to the views rows.
Also, set it to show fields instead of content. And under that configuration, set them to show inline. Check it to hide empty fields.In the view, add a relationship to the flag and check the option to "Include only flagged content". Set the radio button to select the option of any user instead of current user.
Add another relationship: User. This relationship depends on the other relationship that was just mentioned.
Add a field called User: Email address. (this depends on the User relationship) Set it so that it doesn't include the predefined classes. Under Rewrite Results, check the option to rewrite the output and add the token for that same field with a comma after it. (The reason for doing this is so that our email addresses are separated by commas.) Also, check the option to remove HTML tags, the checkmark to remove white spaces, and the checkmark to convert line breaks into HTML
.Under filter criteria set it to only show published content and the type of content you want.
Set the view to show all items instead of using a pager.
Under Contextual filters: Add "Content: ID" and set it to provide a default value if there are none available. In the type dropdown, select Content ID from URL.
I set the caching to none.
In summary; what we are doing with this view is showing all the email addresses for users that have flagged a specific content/node. (And it's filtered by injecting the content's ID via contextual filter argument.)
#3 Set up ECA.
I am using BPMN.io.
It's possible you wouldn't need them all, but I enabled all the ECA sub-modules except for the ECA Cache and ECA Migrate ones. Notice: Install the ECA Tamper module too ( https://www.drupal.org/project/eca_tamper β ). You may need to manually install the Tamper module ( https://www.drupal.org/project/tamper β ) if it doesn't automatically.See screenshot of ECA.
Add the event "Insert content entity" and select the correct bundle/content type.
Add a Render: views action and select your new view. Make sure the correct view display is used. For arguments use "[comment:entity:nid]" (You may need to tweak this..?) Then, add a token name for the output of this action.
Add a "Tamper: find replace (multiline)". Enter the token you just created. In the "Text to find and the replacements" textarea, I have the following:
|
|
So it converts
s to s and removes spaces.
Add a new token name for this output now.Add a "Tamper: strip tags" action entering the new token you just created as the data to be tampered, and enter a new token to be used for what this outputs.
Add a "Tamper: explode" action. Enter the new token. For the string separator use a comma (I think that my be the default..?). Again enter a new token for this output.
After that, add a Gateway (the diamond shaped thingamajig).
After that, add a "List: remove item" action. Enter the last token you created, and set the method to "Drop first" (I think that might be default). Then add a new token for this output (should now be the individual email addresses).
Note: On the arrow between the Gateway diamond and this last "List: remove item" action that we added, set it to "Compare number of list items". Enter the token that we set as the outcome of the action just before it (the "Tamper: explode" action). Set it to Greater than and enter a value of "1" (Note: I set it to 1 instead of 0 because it seemed there was a blank item/email at the end. So to avoid it trying to send an email to a blank address, I did this.)
After the last action ("List: remove item"), enter a new action called: "Send email". For the email address / To field, enter the token with the output from the last action ("List: remove item"). Add your email body. You should be able to use tokens like [comment:entity:title], [comment:url], and [comment:author] in your email body. And set the dropdown to replace tokens: yes.
Add an arrow from this last action that sends the email to the gateway diamond so that it loops through the different email addresses till it gets to the end (or pretty much..).
-----
If you want to set up a notification system for content update instead of comment update, it is very similar. Instead of using the event "Insert Content Entity" at the beginning, set it to "Update Content Entity". And for the first "Render: views" action, set the argument to "[entity:nid]" instead of "[comment:entity:nid]".
I hope I described the setup good enough to help others (maybe even myself in the future :) )
-Caleb