0

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?

1
  • 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.
    – aharown07
    Feb 11, 2023 at 15:24

1 Answer 1

1

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.

2
  • 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.
    – aharown07
    Feb 11, 2023 at 15:32
  • 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.
    – anonymous
    Mar 5, 2023 at 7:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.