3

Using drupal 7 and the Rules module, I'm trying to "create a new entity" of type comment. What it's strange, is that although all the other fields accept tokens, "the main body text" doesn't. Tokens are considered as simple text.

Anyone experienced this and know how to solve it?

2

Have a look at Comment # 10 of the Rules (support) issue titled "Access and Set Comment extra fields ". It includes a Rule example that looks like so:

{ "rules_test" : {
    "LABEL" : "Comment bot",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules" ],
    "ON" : [ "node_update" ],
    "IF" : [
      { "entity_has_field" : { "entity" : [ "node" ], "field" : "field_status" } }
    ],
    "DO" : [
      { "entity_create" : {
          "USING" : {
            "type" : "comment",
            "param_subject" : "zzz",
            "param_node" : [ "node" ],
            "param_author" : [ "node:author" ],
            "param_comment_body" : { "value" : {
                "value" : "This text will be replaced in the next action.",
                "format" : "filtered_html"
              }
            }
          },
          "PROVIDE" : { "entity_created" : { "new_comment" : "New comment" } }
        }
      },
      { "data_set" : {
          "data" : [ "new-comment:comment-body:value" ],
          "value" : [ "node:field-status" ]
        }
      }
   ]
  }
} 

The clue to solve your issue (= work around?) is to use that last Rules Action starting with "data_set".

| improve this answer | |
  • 1
    Thank you for your reply! As a workaround it works! It's strange that this is not implemented by default by the Rules module. – Kropot Oct 20 '16 at 7:52
  • For sure, I was thinking about ways to improve this (for example, translation support is not available, neither HTML support) but I think now it's the best answer, marked as accepted :) – Kropot Oct 20 '16 at 10:30
  • @Kropot : merci for the accept. About "translation support", not sure what exactly you mean by that. But maybe you should create a new question as a followup to this one? If it makes sense, even with some link to this question also? – Pierre.Vriens Oct 20 '16 at 10:36

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.