Score:0

Can a Rules action send an email to all users that have set a flag?

pe flag

I've found some older Drupal 7 info on this, but not much for Drupal 8+ yet. What I want to do:

  • Give users the ability to set a 'notify me' flag on nodes
  • When a comment is added to the flagged node, all users who have flagged it get an email notification

So far...

  • I have the rule set up correctly to allow users in role x to set the flag. It has another action on it that is tested and working.
  • I can select the 'Send email' action.
  • I arrive a set of fields to specify, including the "To" field for an email address. It looks like I can select a flagging uid of users who set a flag.
  • There doesn't appear to be any way to get the email address of a user who flagged into the "To" field.

Maybe this isn't yet possible, but am I perhaps missing something?

pe flag
I tried ECA first on this build. Problem: the flag integration is pretty much just a placeholder at the moment. If you try to get support you'll be informed that the module is not ready. Documentation is sparse and frequently unclear for all the parts of ECA I've explored. I'm excited about the project, but it seems to have quite a ways to go--if you're trying to trigger actions with flags. If rules is "dead," it's a high functioning zombie.
Score:1
cn flag

Custom code approach

I know you asked about Rules module, but I don't think this can be done in Rules. To code this, check out FlagServiceInterface, specifically getFlaggingUsers().

Basically,

  • hook_comment_insert() to act on comment creation.
  • Call getFlaggingUsers() on the node the comment is attached to.
  • Email the users.

Some more hints on coding with Flag 4.x and caveats here.

pe flag
I appreciate the idea. I may figure this out eventually. I've only written a handful of super simple modules, so it usually takes me quite a while to get one working as intended. I'm probably just going to use Comment Notify module for the time being. I was hoping to avoid making users post a comment in order to 'subscribe.' But they are somewhat used to it... though frequently a little annoyed.
fr flag
The Flag module has not committed the port of Rules integration from D7 to D8+. The patch has existed in the Flag issue queue for many years, but the Flag module is not being actively maintained. So, the same thing you did in D7 with Rules and Flag is not possible at this point until Flag is fully ported. This is quite possible with Rules, but it requires that Flag patch to be committed or you need to write your own Rules actions for Flag.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.