function HistoryHooks::commentView
Implements hook_ENTITY_TYPE_view for comment entities.
Attributes
#[Hook('comment_view')]
File
-
core/
modules/ history/ src/ Hook/ HistoryHooks.php, line 111
Class
- HistoryHooks
- Hook implementations for history.
Namespace
Drupal\history\HookCode
public function commentView(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) : void {
if (!$this->currentUser
->isAuthenticated()) {
return;
}
/** @var \Drupal\comment\CommentInterface $entity */
$commented_entity = $entity->getCommentedEntity();
if ($commented_entity?->getEntityTypeId() !== 'node') {
return;
}
$build[$entity->id()]['#attached']['library'][] = 'history/drupal.comment-new-indicator';
// Embed the metadata for the comment "new" indicators on this node.
$build[$entity->id()]['history'] = [
'#lazy_builder' => [
'\\Drupal\\history\\HistoryRenderCallback::lazyBuilder',
[
$commented_entity->id(),
],
],
'#create_placeholder' => TRUE,
];
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.