Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

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
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 –  Krishna Mohan Mar 18 at 14:54
1  
0 = closed, 1 = read only, 2 = read/write –  Felix Eve Mar 18 at 15:13
add comment

1 Answer 1

up vote 4 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
3  
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 at 15:44
add comment

Your Answer

 
discard

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.