2

In Drupal 7, I have set up a rule to automatically close blog comments after two weeks. That works well.

Now, I am trying to have a block displayed on the blog entries when comments are closed. For this, I am using the Rules block visibility module.

I have set up the rule component as per the strict instructions of the module's "readme.txt" file. Without any condition, the export of the component gives this:

{ "rules_set_comments_closed_blocks_after_blog_entry" : {
    "LABEL" : "Display Comments Closed block on blog entries",
    "PLUGIN" : "rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "USES VARIABLES" : {
      "module" : { "label" : "Module", "type" : "text" },
      "delta" : { "label" : "Delta", "type" : "text" },
      "result" : { "label" : "Result", "type" : "boolean", "parameter" : false }
    },
    "DO" : [ { "data_set" : { "data" : [ "result" ], "value" : "1" } } ],
    "PROVIDES VARIABLES" : [ "result" ]
  }
}

The problem I have is with the condition. I cannot find the right data selector in the Data Compare section.

If, on the other hand, I create a rule to display a system message on the site when comments are closed, I do find the data selector item "node:comment" and comparing its value to "NOT 2" (meaning not open) makes the message display only on blog entries with closed comments.

The above exported component works, but on all blog entries whether the comments are closed or not. I just need to add the condition to differentiate nodes with closed comments from those with open comments.

I have tried "entity" has field, entity is of type, etc. But, in components, the list of data selector is still very limited. In fact they are limited to site or current user items.

How can I expand the list of data selectors so that I find my "node:comment" (or similar) selector?

Any help on this is greatly appreciated. :)

1

Head over to the settings of your Rules Component, and specify "Node" as an extra parameter (on top of the 3 you already have in place). You can find "Node" within group "Entity".

After doing so, try again to add "Node" as your data selector, more specifically "Node:comment" (for which you want to test if its value is "0"). This time (after you added that extra parm) it should show up as a data selector.

Here is a sample Rules Component (in export format) that does something similar (it has an extra condition for "uid=1", which is probably not what you want).

{ "rules_block_visibility_hide_block_for_user_1" : {
    "LABEL" : "Hide block for user 1",
    "PLUGIN" : "rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "USES VARIABLES" : {
      "module" : { "label" : "Module", "type" : "text" },
      "delta" : { "label" : "Delta", "type" : "text" },
      "result" : { "label" : "Result", "type" : "boolean", "parameter" : false },
      "node" : { "label" : "Node", "type" : "node" }
    },
    "IF" : [
      { "NOT data_is" : { "data" : [ "site:current-user:uid" ], "value" : "1" } },
      { "data_is" : { "data" : [ "node:comment" ], "value" : "0" } }
    ],
    "DO" : [ { "data_set" : { "data" : [ "result" ], "value" : "1" } } ],
    "PROVIDES VARIABLES" : [ "result" ]
  }
}

If you just import the above Rules Component, it already has that "Node" as an extra parameter.

Note: if you get unexpected errors (after enhancing your Rules Component as suggested above), then enable Rules debugging (so see the Rules debugging log). You can do this via /admin/config/workflow/rules/settings

  • So, this is the way it's done! I would never have figured that one out. But I tried to add the node variable to the component settings and got an error message "The website encountered an unexpected error. Please try again later." I was able to import your component however, make adjustments to it and save it. After configuring the block to accept it, I went to view blog entry pages and I got the same error message. Then same error message when I try to get back to the Rules or Components edit pages. – user14666 Mar 20 '16 at 21:53
  • (Continued) The server error log says nothing. I cannot access the sites log as I get the same error message. Some pages on the site work others produce the error. It's okay since I make automatic backups of the database every 3 hours. This is the first time I get such error. Any idea what might cause the problem? – user14666 Mar 20 '16 at 21:55
  • I was finally able to see the sites log. The description of the error is: "Unable to get variable entity_fetched, it is not defined." That shouldn't be too difficult to fix, any idea? – user14666 Mar 20 '16 at 22:19
  • Looks like my answer helped to have "node" show up for being selected (which is what your question is about). Please consider marking it as such. Also note that it is hard to tell what is causing this new problem. Turn on Rules debugging (cfr the note I added about that). If that doesn't help consider posting a followup question (with a link to this question if needed). – Pierre.Vriens Mar 20 '16 at 23:07
  • Yes, you are right. It looks like a module issue because all goes back to normal once it is disabled. The component then looks fine and produces no error. – user14666 Mar 20 '16 at 23:24

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.