comment_build

Versions
7
comment_build($comment, $node, $build_mode = 'full')

Generate an array for rendering the given comment.

Parameters

$comment A comment object.

$node The node the comment is attached to.

$build_mode Build mode, e.g. 'full', 'teaser'...

Return value

An array as expected by drupal_render().

▾ 3 functions call comment_build()

comment_build_multiple in modules/comment/comment.module
Construct a drupal_render() style array from an array of loaded comments.
comment_preview in modules/comment/comment.module
Generate a comment preview.
comment_reply in modules/comment/comment.pages.inc
This function is responsible for generating a comment reply form. There are several cases that have to be handled, including:

Code

modules/comment/comment.module, line 775

<?php
function comment_build($comment, $node, $build_mode = 'full') {
  // Populate $comment->content with a render() array.
  comment_build_content($comment, $node, $build_mode);

  $build = $comment->content;
  // We don't need duplicate rendering info in comment->content.
  unset($comment->content);

  $build += array(
    '#theme' => 'comment',
    '#comment' => $comment,
    '#node' => $node,
    '#build_mode' => $build_mode,
  );

  $prefix = '';
  $is_threaded = isset($comment->divs) && variable_get('comment_default_mode_' . $node->type, COMMENT_MODE_THREADED) == COMMENT_MODE_THREADED;

  // Add 'new' anchor if needed.
  if (!empty($comment->first_new)) {
    $prefix .= "<a id=\"new\"></a>\n";
  }

  // Add indentation div or close open divs as needed.
  if ($is_threaded) {
    $prefix .= $comment->divs <= 0 ? str_repeat('</div>', abs($comment->divs)) : "\n" . '<div class="indented">';
  }

  // Add anchor for each comment.
  $prefix .= "<a id=\"comment-$comment->cid\"></a>\n";
  $build['#prefix'] = $prefix;

  // Close all open divs.
  if ($is_threaded && !empty($comment->divs_final)) {
    $build['#suffix'] = str_repeat('</div>', $comment->divs_final);
  }

  // Allow modules to modify the structured comment.
  drupal_alter('comment_build', $build);

  return $build;
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.