function history_node_view_alter
Same name in other branches
- 9 core/modules/history/history.module \history_node_view_alter()
- 8.9.x core/modules/history/history.module \history_node_view_alter()
- 10 core/modules/history/history.module \history_node_view_alter()
Implements hook_ENTITY_TYPE_view_alter() for node entities.
File
-
core/
modules/ history/ history.module, line 138
Code
function history_node_view_alter(array &$build, EntityInterface $node, EntityViewDisplayInterface $display) {
if ($node->isNew() || isset($node->in_preview)) {
return;
}
// Update the history table, stating that this user viewed this node.
if ($display->getOriginalMode() === 'full') {
$build['#cache']['contexts'][] = 'user.roles:authenticated';
if (\Drupal::currentUser()->isAuthenticated()) {
// When the window's "load" event is triggered, mark the node as read.
// This still allows for Drupal behaviors (which are triggered on the
// "DOMContentReady" event) to add "new" and "updated" indicators.
$build['#attached']['library'][] = 'history/mark-as-read';
$build['#attached']['drupalSettings']['history']['nodesToMarkAsRead'][$node->id()] = TRUE;
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.