class HistoryController
Same name and namespace in other branches
- 11.x core/modules/history/src/Controller/HistoryController.php \Drupal\history\Controller\HistoryController
Returns responses for History module routes.
Hierarchy
- class \Drupal\Core\Controller\ControllerBase extends \Drupal\Core\DependencyInjection\ContainerInjectionInterface uses \Drupal\Core\Logger\LoggerChannelTrait, \Drupal\Core\Messenger\MessengerTrait, \Drupal\Core\Routing\RedirectDestinationTrait, \Drupal\Core\StringTranslation\StringTranslationTrait
- class \Drupal\history\Controller\HistoryController implements \Drupal\Core\Controller\ControllerBase
Expanded class hierarchy of HistoryController
File
-
core/
modules/ history/ src/ Controller/ HistoryController.php, line 15
Namespace
Drupal\history\ControllerView source
class HistoryController extends ControllerBase {
/**
* Returns a set of nodes' last read timestamps.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The request of the page.
*
* @return Symfony\Component\HttpFoundation\JsonResponse
* The JSON response.
*/
public function getNodeReadTimestamps(Request $request) {
if ($this->currentUser()
->isAnonymous()) {
throw new AccessDeniedHttpException();
}
$nids = $request->request
->get('node_ids');
if (!isset($nids)) {
throw new NotFoundHttpException();
}
return new JsonResponse(history_read_multiple($nids));
}
/**
* Marks a node as read by the current user right now.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The request of the page.
* @param \Drupal\node\NodeInterface $node
* The node whose "last read" timestamp should be updated.
*/
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()));
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.