You are here

function node_comment_block_block_view in Node Comment Block 7

Same name and namespace in other branches
  1. 7.2 node_comment_block.module \node_comment_block_block_view()

Implements hook_block_view().

File

./node_comment_block.module, line 26
Moves the comments for a node into a block.

Code

function node_comment_block_block_view($delta = '') {
  $block = array();
  if ($delta == 'node_comments' || $delta == 'node_comments_secondary') {
    if (arg(0) == 'node' && is_numeric($nid = arg(1)) && !arg(2)) {
      $node = node_load($nid);
      if ($node->comment != 0) {

        // This should be NULL otherwise there will be duplicate h2 elements.
        $block['subject'] = NULL;
        $block['content'] = '';
        global $_node_comment_block_comments;
        if ($comments = $_node_comment_block_comments) {
          $show_form = variable_get('node_comment_block_show_form_' . $delta, 1);
          $show_comments = variable_get('node_comment_block_show_comments_' . $delta, 1);
          if (!$show_form) {
            unset($comments['comment_form']);
          }
          if (!$show_comments) {
            $comments['comments'] = array();
          }
          if ((!$show_comments || empty($comments['comments'])) && !$show_form) {
            return array();
          }
          $block['content'] .= render($comments);
        }
      }
    }
  }
  return $block;
}