1.20.x comment.module comment_build_content(Comment $comment, Node $node, $view_mode = 'full', $langcode = NULL)

Builds a structured array representing the comment's content.

The content built for the comment (field values, comments, file attachments or other comment components) will vary depending on the $view_mode parameter.

Parameters

Comment $comment: A comment object.

Node $node: The node the comment is attached to.

$view_mode: (optional) Display mode, e.g. 'full' or 'teaser'. Defaults to 'full'.

$langcode: (optional) A language code to use for rendering. Defaults to the global content language of the current request.

File

modules/comment/comment.module, line 1005
Enables users to comment on published content.

Code

function comment_build_content(Comment $comment, Node $node, $view_mode = 'full', $langcode = NULL) {
  if (!isset($langcode)) {
    $langcode = $GLOBALS['language_content']->langcode;
  }

  // Remove previously built content, if exists.
  $comment->content = array();

  // Allow modules to change the display mode.
  $view_mode = key(entity_view_mode_prepare('comment', array($comment->cid => $comment), $view_mode, $langcode));

  // Build fields content.
  field_attach_prepare_view('comment', array($comment->cid => $comment), $view_mode, $langcode);
  entity_prepare_view('comment', array($comment->cid => $comment), $langcode);
  $comment->content += field_attach_view('comment', $comment, $view_mode, $langcode);

  $comment->content['links'] = array(
    '#theme' => 'links__comment',
    '#pre_render' => array('backdrop_pre_render_links'),
    '#attributes' => array('class' => array('links', 'inline')),
  );
  if (empty($comment->in_preview)) {
    $comment->content['links']['comment'] = array(
      '#theme' => 'links__comment__comment',
      '#links' => comment_links($comment, $node),
      '#attributes' => array('class' => array('links', 'inline')),
    );
  }

  // Allow modules to make their own additions to the comment.
  module_invoke_all('comment_view', $comment, $view_mode, $langcode);
  module_invoke_all('entity_view', $comment, 'comment', $view_mode, $langcode);

  // Make sure the current display mode is stored if no module has already
  // populated the related key.
  $comment->content += array('#view_mode' => $view_mode);
}