Overrides Drupal\Core\Entity\EntityRenderController::buildContent().
In addition to modifying the content key on entities, this implementation will also set the node key which all comments carry.
Overrides EntityRenderController::buildContent
public function buildContent(array $entities = array(), $view_mode = 'full', $langcode = NULL) {
$return = array();
if (empty($entities)) {
return $return;
}
// Attach user account.
user_attach_accounts($entities);
parent::buildContent($entities, $view_mode, $langcode);
foreach ($entities as $entity) {
$node = node_load($entity->nid);
if (!$node) {
throw new \InvalidArgumentException(t('Invalid node for comment.'));
}
$entity->content['#node'] = $node;
$entity->content['#theme'] = 'comment__node_' . $node
->bundle();
$entity->content['links'] = array(
'#theme' => 'links__comment',
'#pre_render' => array(
'drupal_pre_render_links',
),
'#attributes' => array(
'class' => array(
'links',
'inline',
),
),
);
if (empty($entity->in_preview)) {
$entity->content['links'][$this->entityType] = array(
'#theme' => 'links__comment__comment',
// The "node" property is specified to be present, so no need to check.
'#links' => comment_links($entity, $node),
'#attributes' => array(
'class' => array(
'links',
'inline',
),
),
);
}
}
}