This should be an easy one for someone familiar. I've been at it for a few hours now and searching the forums to no avail.

All i want to do is to show a block only when comments are enabled on a particular node.

I've already tried using the 'Show if the following PHP code returns TRUE (PHP-mode, experts only).' feature but I don't exactly know which variable to test for.

I tried this already, but it only tests to see if a comment has been made, not if they are enabled and even that doesn't quite work correctly:

<?php

if ($node->comment != 0) {
	return TRUE;
} else {
	return FALSE;
}

?>

any ideas?

Comments

ncameron’s picture

Couldn't completely sort it but if you do a var_dump of $node->links you'll see it changes depending on if comments are allowed or not. You should be able to cook something up from that.

Good luck
Neil
--
Drupal Development for Pleasure and Profit
http://drupal.altate.ch

ekendra’s picture

Interesting.

var_dump ($node->links);

brings up NULL. huh? This is from the block code itself. Can't understand that. any clues?

After some trial and error I've determined that the $node variable isn't available for the block function or for the TRUE/FALSE test.

How else am I supposed to test whether or not comments are enabled? Freaky.

ekendra’s picture

anyone?

I tried summoning $node as a global and then performing the TRUE/FALSE test but nothing.

ekendra’s picture

Didn't expect this one to be ignored by the purportedly 'active' Drupal community.

All I want to do is to show a block on nodes only when comments are enabled on that node.

Surely there is a solution?

ekendra’s picture

Finally hacked something out that worked.

<?php
$match = FALSE;
$enabledCheck = 2;
if (arg(0) == 'node' && is_numeric(arg(1))) {
  $nid = arg(1);
  $node = node_load(array('nid' => $nid));
  $commentSetting = $node->comment;
  if ($commentSetting == $enabledCheck) {
    $match = TRUE;
  }
}
return $match;
?>

Go-run-gaa-!!