Drupal Answers is a question and answer site for Drupal developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
$node = node_load($argument); $result = $node->comment; if $result is 1 then comment status is closed. if it is 2 then status is open – Krishna Mohan Mar 18 '14 at 14:54
0 = closed, 1 = read only, 2 = read/write – Felix Eve Mar 18 '14 at 15:13
up vote 5 down vote accepted

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.

share|improve this answer
I just updated that page on drupal.org. There are constants for this: COMMENT_NODE_HIDDEN, COMMENT_NODE_CLOSED, and COMMENT_NODE_OPEN. – MPD Mar 18 '14 at 15:44

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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