W3cubDocs

/Drupal 8

function history_write

history_write($nid, $account = NULL)

Updates 'last viewed' timestamp of the specified entity for the current user.

Parameters

$nid: The node ID that has been read.

$account: (optional) The user account to update the history for. Defaults to the current user.

File

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

Code

function history_write($nid, $account = NULL) {

  if (!isset($account)) {
    $account = \Drupal::currentUser();
  }

  if ($account->isAuthenticated()) {
    db_merge('history')
      ->keys(array(
        'uid' => $account->id(),
        'nid' => $nid,
      ))
      ->fields(array('timestamp' => REQUEST_TIME))
      ->execute();
    // Update static cache.
    $history = &drupal_static('history_read_multiple', array());
    $history[$nid] = REQUEST_TIME;
  }
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!modules!history!history.module/function/history_write/8.1.x