function WorkspacesTestHooks::incrementHookCount

Increments the invocation count for a specific entity hook.

Parameters

string $hook_name: The name of the hook being invoked (e.g., 'hook_entity_create').

\Drupal\Core\Entity\EntityInterface $entity: The entity object involved in the hook.

4 calls to WorkspacesTestHooks::incrementHookCount()
WorkspacesTestHooks::entityCreate in core/modules/workspaces/tests/modules/workspaces_test/src/Hook/WorkspacesTestHooks.php
Implements hook_entity_create().
WorkspacesTestHooks::entityInsert in core/modules/workspaces/tests/modules/workspaces_test/src/Hook/WorkspacesTestHooks.php
Implements hook_entity_insert().
WorkspacesTestHooks::entityPresave in core/modules/workspaces/tests/modules/workspaces_test/src/Hook/WorkspacesTestHooks.php
Implements hook_entity_presave().
WorkspacesTestHooks::entityUpdate in core/modules/workspaces/tests/modules/workspaces_test/src/Hook/WorkspacesTestHooks.php
Implements hook_entity_update().

File

core/modules/workspaces/tests/modules/workspaces_test/src/Hook/WorkspacesTestHooks.php, line 85

Class

WorkspacesTestHooks
Hook implementations for workspaces_test.

Namespace

Drupal\workspaces_test\Hook

Code

protected function incrementHookCount(string $hook_name, EntityInterface $entity) : void {
    $key = $entity->getEntityTypeId() . '.' . $hook_name . '.count';
    $count = $this->keyValueFactory
        ->get('ws_test')
        ->get($key, 0);
    $this->keyValueFactory
        ->get('ws_test')
        ->set($key, $count + 1);
}

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