function comment_build_content
7.x comment.module | comment_build_content($comment, $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: A comment object.
$node: The node the comment is attached to.
$view_mode: View mode, e.g. 'full', 'teaser'...
$langcode: (optional) A language code to use for rendering. Defaults to the global content language of the current request.
1 call to comment_build_content()
- comment_view in drupal-7.x/
modules/ comment/ comment.module - Generate an array for rendering the given comment.
File
- drupal-7.x/
modules/ comment/ comment.module, line 987 - Enables users to comment on published content.
Code
function comment_build_content($comment, $node, $view_mode = 'full', $langcode = NULL) {
if (!isset($langcode)) {
$langcode = $GLOBALS['language_content']->language;
}
// Remove previously built content, if exists.
$comment->content = array();
// Allow modules to change the view mode.
$context = array(
'entity_type' => 'comment',
'entity' => $comment,
'langcode' => $langcode,
);
drupal_alter('entity_view_mode', $view_mode, $context);
// 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('drupal_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 view mode is stored if no module has already
// populated the related key.
$comment->content += array('#view_mode' => $view_mode);
}