Having a view of comment fields here that is embedded into another view via Views Field View module. The comment view has a contextual filter: the nid. Works quite nice.

Now I want to hide the view if comments ain't allowed (per node). Of course I have the node's ID as $argument. How can I check the comment status from that to specify the validate criteria?

  • 2
    $node = node_load($argument); $result = $node->comment; if $result is 1 then comment status is closed. if it is 2 then status is open Mar 18, 2014 at 14:54
  • 1
    0 = closed, 1 = read only, 2 = read/write
    – Felix Eve
    Mar 18, 2014 at 15:13

1 Answer 1


The following code should do the trick:

$node = node_load($argument); // load the node object based on the nid
if($node->comment == COMMENT_NODE_CLOSED) {
  // comments are closed - hide the view

There are 3 constants that define the different comment states:

For more information see the Node object reference.

  • 3
    I just updated that page on drupal.org. There are constants for this: COMMENT_NODE_HIDDEN, COMMENT_NODE_CLOSED, and COMMENT_NODE_OPEN.
    – mpdonadio
    Mar 18, 2014 at 15:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.