Action to set node commenting to read only

Events happening in the community are now at Drupal community events on www.drupal.org.
wgrunberg's picture

Hi,

I have been looking for an action to set a node's commenting status to read only (deny new comments). My rules trigger and condition - changes in a CCK field - works fine but I am struggling with the action part. The following "read/write" to "read only" toggle code example looks promising but I can't get it to work in my Drupal 6 environments. Could somebody help me with my poor PHP skills?

<?php
if(!module_exists("comment"))
    return;
if(
$enabled)
   
$status = COMMENT_NODE_READ_WRITE;
else
   
$status = COMMENT_NODE_READ_ONLY;
$node->comment = $status;

return array(
"node" => $node);
?>

I am getting the flowing error:
Parse error: syntax error, unexpected $end, expecting '(' in /drupal6/sites/all/modules/rules/rules/modules/php.rules.inc(107) : eval()'d code on line 1

I have tried dumbing it down but still get the same error:

<?php
$status
= COMMENT_NODE_READ_ONLY;
$node->comment = $status;
return array(
"node" => $node);
?>

Comments

Newbie error: do not include <?php ?> in rules

wgrunberg's picture

The code worked fine once I removed the PHP tags. Apparently, the PHP tags are used as some form of pre-processing before execution.

Rules

Group organizers

Group categories

Categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: