You are here

function entity_metadata_view_comment in Entity API 7

Callback to view comments.

1 string reference to 'entity_metadata_view_comment'
_entity_info_add_metadata in ./entity.module
Adds metadata and callbacks for core entities to the entity info.

File

modules/callbacks.inc, line 968
Provides various callbacks for the whole core module integration.

Code

function entity_metadata_view_comment($entities, $view_mode = 'full', $langcode = NULL) {
  $build = array();
  $nodes = array();

  // The comments, indexed by nid and then by cid.
  $nid_comments = array();
  foreach ($entities as $cid => $comment) {
    $nid = $comment->nid;
    $nodes[$nid] = $nid;
    $nid_comments[$nid][$cid] = $comment;
  }
  $nodes = node_load_multiple(array_keys($nodes));
  foreach ($nid_comments as $nid => $comments) {
    $node = isset($nodes[$nid]) ? $nodes[$nid] : NULL;
    $build += comment_view_multiple($comments, $node, $view_mode, 0, $langcode);
  }
  return array(
    'comment' => $build,
  );
}