I have a function in a module that does:

function mymodule_preprocess_node(&$variables) {
  if ($variables['type']=='forum') {
    $variables['node']->comment = 1;
  }
}

which should make the comment form become read-only for the current (forum) node.

Unfortunately, this does not work, the full comment form is rendered. Setting the

$variables['node']->comment = 0;

works, it removes the complete comment form

The line that is causing this discrepancy is line 1050 in the comment.module

    if (user_access('post comments') && node_comment_mode($nid) == COMMENT_NODE_READ_WRITE && (variable_get('comment_form_location_'. $node->type, COMMENT_FORM_SEPARATE_PAGE) == COMMENT_FORM_BELOW) && !$reply) {

more, specifically, it is
node_comment_mode($nid) == COMMENT_NODE_READ_WRITE

The node_comment_mode function does a database-dip, and therefore retrieves the original value, instead of the value that is set in my module.

Changing the said statement to

$node->comment == COMMENT_NODE_READ_WRITE

solves that issue. I guess perhaps checking for the existence of the ->comment property in the line previous line makes sense (and still calling node_comment_mode if it doesn't)

Comments

brianV’s picture

Version: 6.11 » 6.x-dev

batje,

Perhaps it is best to do something like:


if (isset($node->comment)) {
  $comment_mode =  $node->comment;
}
else {
  $comment_mode = node_comment_mode($nid);
}

And then using the $comment_mode variable in place of node_comment_mode($nid) in line 1050.

Thoughts?

brianV’s picture

Status: Active » Needs review
StatusFileSize
new1.46 KB

Can you test this patch to ensure that it works?

Anonymous’s picture

Category: bug » support
Status: Needs review » Closed (cannot reproduce)

No response from OP, closing.