1

I need to send a notification to the article owner when some user comments on the review added to an article.

But in the Rules module, while adding a Rules Action, there is this action: 'Send notification to user when flag is applied' (part of a custom module I inherited from a prior mantainer of this site). With this action, notification is only sent to the reviewer, not the article owner.

Can anyone help to get this to work? Or is there another way to make this work without the custom module I'm struggling with?

Here is my rule:

{ "rules_send_notification_when_commented_on_article_listing" : {
    "LABEL" : "send notification when commented on article\/listing",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "user_notifications", "comment" ],
    "ON" : { "comment_insert" : [] },
    "IF" : [
      { "entity_is_of_bundle" : {
          "entity" : [ "comment" ],
          "type" : "comment",
          "bundle" : { "value" : {
              "comment_node_article" : "comment_node_article",
              "comment_node_page" : "comment_node_page",
              "comment_node_comment" : "comment_node_comment",
              "comment_node_company" : "comment_node_company",
              "comment_node_review" : "comment_node_review"
            }
          }
        }
      },
      { "NOT data_is" : { "data" : [ "comment:node:author" ], "value" : [ "comment:author" ] } }
    ],
    "DO" : [
      { "user_notifications_action_send_notification_flag" : {
          "flag_as_flag" : "commented",
          "content" : [ "comment:node" ],
          "message" : "commeted on ",
          "heading" : "d"
        }
      }
    ]
  }
}
  • Comments have been removed. Please don't use them for extended discussion; instead, include the relevant part in the question. – kiamlaluno Mar 16 '17 at 15:43
0

As per the "Or is there another way to make this work without the custom module I'm struggling with?" in your question, IMO the answer is yes. Read on for more details about how to "send a notification to the article owner when some user comments on the review added to an article." (as in your question).

Have a look at this, rather basic, rule (in Rules export format):

{ "rules_notify_node_author_about_new_comment" : {
    "LABEL" : "Notify node author about new comment",
    "PLUGIN" : "reaction rule",
    "ACTIVE" : false,
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "comment" ],
    "ON" : { "comment_insert" : [] },
    "IF" : [
      { "NOT data_is" : { "data" : [ "comment:node:author" ], "value" : [ "comment:author" ] } }
    ],
    "DO" : [
      { "mail" : {
          "to" : [ "comment:node:author:mail" ],
          "subject" : "A new comment was posted to the node you authored",
          "message" : "A new comment was posted, you can find it at [comment:url]",
          "language" : [ "" ]
        }
      }
    ]
  }
}

Use the Rule UI to import it in your own environment. Some more details about this rule:

  • Event: After saving a new comment.
  • Condition: Check that the user who posted the comment is different from the node author (I'd think it doesn't make sense to notify the node author of comments posted by the node author, right?).
  • Action: Send an eMail to the node author, with a link to the comment that got posted.

Feel free to add any rules conditions that may fit to further improve the above prototype, to fit your actual requirements.

Note that the above rule doesn't depend on any other module, though you could make it way more sophisticated if you'd also get the Message module involved (eg to create a log file of all such eMails ever being produced, if that's what you'd want to do).

BTW: no need for custom code ...

  • Thanks for your effort @Pierre.Vriens, but I think you are not yet clarified about the 'notification' part. By notification, I meant, notifications as that in face book and all, which are in the site itself. Also in your rule, you have set the to address:[comment:node:author:mail], which I have tried using custom code. It will sent mail only to the reviewer, not the owner, – bincy Mar 17 '17 at 4:04
  • @bincy I bet you are not really familiar yet with how things work on this site (eg: because you have not earned the "informed" badge yet, as shown in your profile). So please have a look at this, especially the bold phrase in the last paragraph. Also: (1) the "notification" requirement you now added in this comment, should have been included in your actual question, how about you make that a followup question (with link to this one)? (2) "We" cannot help here with debugging custom code not shown (I'm pretty sure about that token). – Pierre.Vriens Mar 20 '17 at 10:28
  • Solved it by writing a query to directly insert the notification into the table. – bincy Mar 22 '17 at 8:22
  • @bincy merci for the update. Maybe you should post your own answer with the code/query included, so that others can learn from your own answer, and you can mark your question as solved (by marking your own answer as accepted)? That way the question wil also no longer show up as unanswered. – Pierre.Vriens Mar 22 '17 at 8:49

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.