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?