history_node_view_alter

history_node_view_alter(array &$build, EntityInterface $node, EntityViewDisplayInterface $display)

Implements hook_ENTITY_TYPE_view_alter() for node entities.

File

core/modules/history/history.module, line 135
Records which users have read which content.

Code

function history_node_view_alter(array &$build, EntityInterface $node, EntityViewDisplayInterface $display) {
  // 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;
    }
  }

}
doc_Drupal
2016-10-29 09:17:43
Comments
Leave a Comment

Please login to continue.