function comment_view_multiple

comment_view_multiple($comments, $node, $view_mode = 'full', $weight = 0, $langcode = NULL)

Construct a drupal_render() style array from an array of loaded comments.

Parameters

$comments: An array of comments as returned by comment_load_multiple().

$node: The node the comments are attached to.

$view_mode: View mode, e.g. 'full', 'teaser'...

$weight: An integer representing the weight of the first comment in the list.

$langcode: A string indicating the language field values are to be shown in. If no language is provided the current content language is used.

Return value

An array in the format expected by drupal_render().

File

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

Code

function comment_view_multiple($comments, $node, $view_mode = 'full', $weight = 0, $langcode = NULL) {
  $build = array();
  $entities_by_view_mode = entity_view_mode_prepare('comment', $comments, $view_mode, $langcode);
  foreach ($entities_by_view_mode as $entity_view_mode => $entities) {
    field_attach_prepare_view('comment', $entities, $entity_view_mode, $langcode);
    entity_prepare_view('comment', $entities, $langcode);

    foreach ($entities as $entity) {
      $build[$entity->cid] = comment_view($entity, $node, $entity_view_mode, $langcode);
    }
  }

  foreach ($comments as $comment) {
    $build[$comment->cid]['#weight'] = $weight;
    $weight++;
  }
  // Sort here, to preserve the input order of the entities that were passed to
  // this function.
  uasort($build, 'element_sort');
  $build['#sorted'] = TRUE;

  return $build;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/modules!comment!comment.module/function/comment_view_multiple/7.x