function history_write

Same name and namespace in other branches
  1. 9 core/modules/history/history.module \history_write()
  2. 10 core/modules/history/history.module \history_write()
  3. 11.x core/modules/history/history.module \history_write()

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


$nid: The node ID that has been read.

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

2 calls to history_write()
HistoryController::readNode in core/modules/history/src/Controller/HistoryController.php
Marks a node as read by the current user right now.
HistoryLegacyTest::testHistoryAttachTimestamp in core/modules/history/tests/src/Kernel/HistoryLegacyTest.php
Tests history_attach_timestamp() deprecation.


core/modules/history/history.module, line 106


function history_write($nid, $account = NULL) {
    if (!isset($account)) {
        $account = \Drupal::currentUser();
    if ($account->isAuthenticated()) {
            'uid' => $account->id(),
            'nid' => $nid,
            'timestamp' => REQUEST_TIME,
        // Update static cache.
        $history =& drupal_static('history_read_multiple', []);
        $history[$nid] = REQUEST_TIME;

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.