You are here

function hook_hooks_example_count_incremented in Examples for Developers 3.x

Same name and namespace in other branches
  1. 8 hooks_example/hooks_example.api.php \hook_hooks_example_count_incremented()

Respond to node view count being incremented.

This hooks allows modules to respond whenever the total number of times the current user has viewed a specific node during their current session is increased.

Parameters

int $current_count: The number of times that the current user has viewed the node during this session.

\Drupal\node\NodeInterface $node: The node being viewed.

Related topics

1 function implements hook_hooks_example_count_incremented()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

hooks_example_hooks_example_count_incremented in modules/hooks_example/hooks_example.module
Implements hook_hooks_example_count_incremented().
1 invocation of hook_hooks_example_count_incremented()
hooks_example_node_view in modules/hooks_example/hooks_example.module
Implements hook_ENTITY_TYPE_view().

File

modules/hooks_example/hooks_example.api.php, line 43
Hooks specific to the Hooks Example module.

Code

function hook_hooks_example_count_incremented($current_count, \Drupal\node\NodeInterface $node) {

  // If this is the first time the user has viewed this node we display a
  // message letting them know.
  if ($current_count === 1) {
    \Drupal::messenger()
      ->addMessage(t('This is the first time you have viewed the node %title.', [
      '%title' => $node
        ->label(),
    ]));
  }
}