5

When I write a comment on a node, I want to be able to select the users that will get a notification (via e-mail) about that new comment. Basecamp has this feature and I think it is very cool.

Is this possible without customization? I know how to notify the author of the comment, but this is different.

  • I can't find the link, but read this links cocomore.com/blog/… and tylerfrankenstein.com/code/… – Adrian Cid Almaguer Dec 5 '15 at 23:22
  • @AdrianCidAlmaguer nice tutorials, but he might want to send them to specific users and not to all users of a role. – No Sssweat Dec 6 '15 at 2:41
  • 1
    To reduce the risk that your question gets closed (as 'off topic'), I suggest you edit your question to better explain what that Basecamp feature is about (what it does). Maybe also add a relevant link to it ... PS: popular questions get closed also ... – Pierre.Vriens Dec 7 '15 at 14:02
  • Jose, did you try my answer? – No Sssweat Dec 20 '15 at 4:10
6

When I write a comment on a node, I want to be able to select the users that will get a notification about that new comment.

1) Download Rules and Entity Reference Modules.

2) Enable Rules, Rules UI (User Interface, we need this), and Entity Reference

3) In your comment fields

  • Add a field with Entity Reference and a widget of Auto complete (tag style)

For example: I named mine lalala (click picture below to enlarge)

enter image description here

4) In your field settings:

  • Select User as your target type

enter image description here

After you click save field settings you are taken to another screen, scroll down and find Number of values and change it to Unlimited and Save Changes.

enter image description here

5) Add a new rule by going to /admin/config/workflow/rules/reaction/add

  • React on Event: After Saving New Comment
  • Restrict by Type: Select your content type (In this example it's Article Comments, since in Articles Comments is where I put my lalala field.)

enter image description here

6) Click on Add a Loop

  • Data selector: comment:field-lalala (remember I named my entity reference field lalala) enter image description here

7) Click Add Action, but the one from the loop!

enter image description here

8) Select Fetch Entity by Property

  • Entity Type: User
  • Property: Email
  • Data Selector: list-item:mail
  • Limit Result Count: put a large number here in case it has an effect. (since we are looping, I don't believe so, but I am not 100% sure)

enter image description here

9) Add another action to the loop, this time add Send Mail

Click on switch to data selection button.

enter image description here

To: list-item:mail

enter image description here

The end result should look like this

enter image description here

Now add a new comment.

On your entity reference field since we are using Autocomplete (tag style) you start to type a user name and select the user. Then add a comma , to add more users

Ex: enter image description here

After posting the comment, all referenced users should receive an e-mail.

  • 1
    Even though I've not qa-tested this approach, I can see this answer work "also". And I must admit it's a great sample of how Drupal can be considered as a (virtual) Lego-toy (I might refer to it in my future Drupal classes ...). Therefor +1 ... But I'm not sure to what extend this solution satisfies the "without customization" (as in the question) ... it'll depend what the definition of that from the OPer will be (if it is iike "using site building techniques only" then you're fine of course). I'd also be interested in knowing about the performance of this solution (in a huge site). – Pierre.Vriens Dec 7 '15 at 9:55
  • 1
    @Pierre.Vriens I can guarantee this is a working solution as I tested this before posting the answer. For performance, I don't believe it will be an issue, as the auto complete only shows a limited amount of options, as you keep typing it narrows them down. Ex: Typing F will not show/return all users that start with F, but it would only show say around 5 or so. You need keep typing more letters in order to make it show say "Francis", which may not be shown when you just type F. – No Sssweat Dec 7 '15 at 10:11
  • 1
    OK, thanks for the extra clarification. Let's wait and see what OPer is going to provide as possible extra feedback to either answer. – Pierre.Vriens Dec 7 '15 at 10:17
  • @NoSssweat hi there, thanks for your answer but cant get it to work. i follow your guide but im having problems creating the loop. when i put node:field-notificar on Loop data-selector i got error, see the image. i tried with comment:field-notificar but same result. i.imgur.com/KOQGvK4.png – Jose San Pedro Dec 28 '15 at 14:32
  • @JoseSanPedro hummm that is odd, double check that you did steps 3 to 6 correctly. Did you add the entity reference field to your comment fields and not to your node fields? Did you set the value to unlimited? Did you change the widget to Auto complete (tag style)? Did you Restrict by Type your rule? – No Sssweat Dec 28 '15 at 22:56
2

To my knowledge this is NOT possible only usiing Drupal core, so you'll have to do some "customization". So far the bad news ... The good news is that you can use the Rules module to create a rule to send such notifications.

However the challenge in your question is "which users should get the notifications". If you'd have dozens, or hundreds (or thousands?) of users, using something like a select list doesn't seem like an option to me. Therefor I'd recommend you to use the Flag module to have each user indicate something like "Notify these users whenever I post comments" (using so called "private" flags).

With both Rules and Flag in place, it's a piece of cake to then send notifications of comments that get posted to the users flagged by the author of the comment. To do so, I'd recommend you to also have a look at the Community documentation about the Message Stack, which allows you to do way more then just "sending an eMail".

The previous approach will always send such notifications to the same set of (flagged) users, for each comment posted by a single user. Unless the list of flagged users is adapted before posting a new comment (by flagging more users, or unflagging some previously flagged users). However, by also using the Flag Lists module you could make this more flaxible. I.e. each user can create his/her own set of flags (similar to "Google circles"?). Some more details about Flag Lists (from its project page):

Flag lists allows regular users to create unlimited private flags called lists. Flag lists extends Flag. In Flag, a site administrator creates the flags that any authorized users may use. In Flag lists, users create their own lists, and they may only add to their own lists.

  • Thanks, ill take a look at those modules. But i think it is not exactly what i want to do... :( The way you propose, is like create a general notification rule for each comment author and i want to be able to do this whenever a user will post a comment...he can select users to receive a notification... – Jose San Pedro Dec 6 '15 at 23:59
  • Unfortunately with flags, you don't control who flags the content. I have provided a direct answer to the question. Although, this solution is nice if you want to implement a "follow a user" type of notification. Ex: Notify me every time Jose posts a comment on the website. – No Sssweat Dec 7 '15 at 5:11
  • 1
    @NoSssweat : you're right that one can use the fag module to implement such "follow a user". But the solution in my answer here is the other way around, as per the "Notify these users whenever 'I' post comments". Wouldn't you agree (maybe after reading it again)? – Pierre.Vriens Dec 7 '15 at 9:49
  • ok I agree, the short coming of this method, you may not want to notify the same users for all your comments. Perhaps in comment X you do not want to notify Jose but in comment Y you do want to notify Jose. – No Sssweat Dec 7 '15 at 10:00
  • 1
    When I first wrote my answer I wondered if I should yes/no add the "Flag Lists" variation also ... As per the previous comment, it seems it may make sense, so I just enhanced my answer ... "Google circles" implemented in Drupal (instead of "Basecamp") ... – Pierre.Vriens Dec 7 '15 at 10:13

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.