- Issue created by @Janner
- 🇩🇪Germany jurgenhaas Gottmadingen
Views always comes to mind when you need to query the database. In this case, you could create a view that returns all users who have flagged the given node, which is forwarded to the view as a contextual filter.
In ECA, you execute that view and then loop through the received users to send them your email.
- 🇬🇧United Kingdom Janner
@jurgenhaas
That's really helpful and has got me closer, thank you!
Where I'm failing now is identifying how to correctly enter the argument for the desired contextual filter on the ECA Views: Execute query action.
On the view configuration page, the contextual filter is:
(Flags) Flagging: Entity ID
On the ECA action configuration page I've tried entering various tokens and text, but none appear to be correct. Looking at the logs, the ECA model is running and accessing the view. In fact, it's running a test successor to the Views: Execute query action.
I've looked at several models in the model library, but none of these used an argument for this action.
Would someone please offer some guidance on the correct way to enter the contextual filter in the Views: Execute query action?
Many thanks!
- 🇩🇪Germany jurgenhaas Gottmadingen
You have available the node, that has been updated. And you want to forward the ID of that node to the view as an argument. So, in ECA you provide
[node:nid]
as the argument.You then have to build your view such that the node ID is your contextual filter for which you want to query all the flaggings and their associated users.
- 🇬🇧United Kingdom Janner
@jurgenhaas
Thank you. I appreciate the pointers.
- 🇬🇧United Kingdom Janner
Unfortunately, I have been unable to successfully implement this functionality. I have a view that utilizes filters and relationships to display users who have flagged a specific node, but I have been unable to determine how to use this view with my ECA model in order to generate an email recipient list. This is due to the limits of my own capabilities, and not those of ECA!
In the past, many Drupal 6 and 7 users(myself included( utilized a combination of the Rules and Flag modules to create comment notification systems, and I believe that ECA could be a great tool for achieving similar functionality now. For my own use case, the ability to easily utilise conditions and custom emails for different situations would offer a attractive alternative to other notification options currently available.
Accordingly, if anyone has been able to successfully implement an ECA model for this purpose, I would greatly appreciate it if you could share your solution here. This would not only benefit myself but also others who may be looking to implement the same functionality. Thank you.
- 🇩🇪Germany jurgenhaas Gottmadingen
The important thing about using views in ECA is to first determine what type of entity you want to receive from the view. That is then the entry point for building the view. In this case here, you want to receive a list of users, therefore, when creating a new view it needs to be a new view for users.
As you want to receive those users only, who flagged the node which just got commented, you need to add a chain of relationships:
- Flags: link from the user to all its flags
- Node: link from the flag to the related node
- Comment: link from the node to all related comments
Now, that would return all users who have flagged any node that has a comment. As you only want those for a specific comment, you add a contextual filter to that view on the comment ID. From that on, this view will only return those users who have flagged the node with a given comment.
In ECA, you then call that view and use the current comment ID as the argument.
- 🇬🇧United Kingdom Janner
@jurgenhaas
This is really helpful. Thank you!
I'll give this another shot this week.
- 🇪🇬Egypt rami.sedhom
@jurgenhaas your comment #8 is very helpful and I'm trying to follow it. The problem is from Users view, I can't link to flags. I can only link to: "File", "Content authored", "Representative node". May be I'm missing something. Would you please advice?
- 🇩🇪Germany jurgenhaas Gottmadingen
@rami.sedhom could you probably explain your use case? I'm not understanding the question in #10 but with some more detail, we might be able to help.
- 🇪🇬Egypt rami.sedhom
Thanks @jurgenhaas for your fast response. I've the same use case as @Janner: "create an ECA model that sends an email notification to users when a new comment is posted to a node they have flagged."
Following your advice in #8:
In this case here, you want to receive a list of users, therefore, when creating a new view it needs to be a new view for users.
As you want to receive those users only, who flagged the node which just got commented, you need to add a chain of relationships:
Flags: link from the user to all its flags
Node: link from the flag to the related node
Comment: link from the node to all related commentsSo I created a new view for users. And when I start first relationship with Flags, I'm not able to because Flags is not available
- 🇩🇪Germany jurgenhaas Gottmadingen
Ah, OK. I missed the view context here. So, if there is no relationship available between flags and their users, that means that the flag module is not providing them in their views data. This should be added in the flag module. Maybe you can ask them to add that?
- Status changed to Postponed: needs info
over 1 year ago 9:28am 30 June 2023 - Status changed to Closed: outdated
8 months ago 1:54pm 2 April 2024 - 🇨🇷Costa Rica calebyoder
Hi there!
I posted this on the issue page that's referenced here in comment #15, but thought I'd post here as well...
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
<br>
.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:
<br>|<span></span> |
So it converts
<br>
s to<span>
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