Enable / Disable comment form in a module? I would like to set a given node's comment flag to 1 or 2 (to either show or hide the comment form) via my custom module, depending on certain conditions.

I have tried using hook_node_view, but this approach seems not to have worked:


function custom_node_view($node, $view_mode, $langcode) {
  $node->comment = 1;
}


Even if I explicitly set the comment flag to 1, it will remain 2 for a given node. If I dpm($node); just after setting the flag, the correct value will show in the devel information, but the comment form will still show...

According to comment.module, the values are such:

/**
 * Comments for this node are closed.
 */
define('COMMENT_NODE_CLOSED', 1);

/**
 * Comments for this node are open.
 */
define('COMMENT_NODE_OPEN', 2);


Is there a different hook I should be using to show/hide the comment form programmatically?
It looks like I can set the comment display correctly within hook_node_load(). I guess that runs a bit earlier in the process, and tells comment.module to not display the form for a given node.

Here's an example of what I ended up implementing:

&lt;?php
/**
 * Implements hook_node_load().
 */
function custom_node_load($nodes, $types) {
  foreach ($nodes as $node) {
    $node-&gt;comment = COMMENT_NODE_CLOSED; // to close comments
  }
}
?&gt;