2

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

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.

| 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. – mpdonadio Mar 18 '14 at 15:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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