You are here

public function HistoryController::readNode in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/history/src/Controller/HistoryController.php \Drupal\history\Controller\HistoryController::readNode()
  2. 9 core/modules/history/src/Controller/HistoryController.php \Drupal\history\Controller\HistoryController::readNode()

Marks a node as read by the current user right now.

Parameters

\Symfony\Component\HttpFoundation\Request $request: The request of the page.

\Drupal\node\NodeInterface $node: The node whose "last read" timestamp should be updated.

1 string reference to 'HistoryController::readNode'
history.routing.yml in core/modules/history/history.routing.yml
core/modules/history/history.routing.yml

File

core/modules/history/src/Controller/HistoryController.php, line 46

Class

HistoryController
Returns responses for History module routes.

Namespace

Drupal\history\Controller

Code

public function readNode(Request $request, NodeInterface $node) {
  if ($this
    ->currentUser()
    ->isAnonymous()) {
    throw new AccessDeniedHttpException();
  }

  // Update the history table, stating that this user viewed this node.
  history_write($node
    ->id());
  return new JsonResponse((int) history_read($node
    ->id()));
}