2

I am using "Comments" as a note option. I want to let users add the same comment to multiple nodes with the Views Bulk Operations (VBO) module.

How do I get the "Add Comment Form" in VBO to achieve this?

0
1

Step 1

Use the Rules module to create a Rules Component, which includes whatever Rules Conditions you might need (if any), and with a Rules Action to create an entity, of type "Comment", whereas you specify some relevant parameters for that Rules Component, such as:

  • The node to which the comment is to be added.
  • The relevant options for the actual comment (such as the actual text of the comment).

Below is an example of a Rules Action that creates a comment (in Rules export format, use the Rules UI to import it in your own site):

{ "rules_add_a_comment_to_a_node" : {
    "LABEL" : "Add a comment to a node",
    "PLUGIN" : "rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "USES VARIABLES" : {
      "comment_node" : { "label" : "Node to add comment", "type" : "node" },
      "comment_body" : { "label" : "Comment body", "type" : "text_formatted" },
      "comment_subject" : { "label" : "Comment subject", "type" : "text" }
    },
    "IF" : [
      { "user_has_role" : {
          "account" : [ "site:current-user" ],
          "roles" : { "value" : { "2" : "2" } }
        }
      }
    ],
    "DO" : [
      { "entity_create" : {
          "USING" : {
            "type" : "comment",
            "param_subject" : [ "comment-subject" ],
            "param_node" : [ "comment-node" ],
            "param_author" : [ "site:current-user" ],
            "param_comment_body" : [ "comment-body" ]
          },
          "PROVIDE" : { "entity_created" : { "comment_created" : "Created comment" } }
        }
      }
    ]
  }
}

Step 2

Create a view of the nodes to which some comment is to be added. Then transform that view into a view that uses Views Bulk Operations, and use the technique documented in "How to use Rules to create a custom bulk operation for a VBO view?". In doing so, you'll then be able to use the Rules Component from Step 1.

PS: this answer is for D7 ...

4
  • @GirishCholayill : I'm about sure that all you need to do is to change "text_formatted" (in line 8 of my exported rule sample) to just "text" (which you can also do I think in the Rules UI, by changing the data type there). Maybe also have a look at the sample rule in this answer (there is a way to do this, I just don't know anymore by heart). Jan 26 '17 at 13:57
  • I did try that, but it was giving me error. That's alright, I'll check it up. Thanks a lot for the help. Appreciate it. Jan 26 '17 at 14:03
  • Its working now, it was an error in my content editor. Jan 26 '17 at 14:36
  • @GirishCholayill : aha, it was only that ... time to cleanup some "extended discussions" comments around here (= delete them), before a mod moves them to chat (which I don't like at all). Greetings! Jan 26 '17 at 14:41

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.