function WorkspacesTestHooks::entityPresave

Same name and namespace in other branches
  1. main core/modules/workspaces/tests/modules/workspaces_test/src/Hook/WorkspacesTestHooks.php \Drupal\workspaces_test\Hook\WorkspacesTestHooks::entityPresave()

Implements hook_entity_presave().

Attributes

#[Hook('entity_presave')]

File

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

Class

WorkspacesTestHooks
Hook implementations for workspaces_test.

Namespace

Drupal\workspaces_test\Hook

Code

public function entityPresave(EntityInterface $entity) : void {
  $this->incrementHookCount('hook_entity_presave', $entity);
  if (!$this->workspaceInformation
    ->isEntitySupported($entity)) {
    return;
  }
  /** @var \Drupal\Core\Entity\RevisionableInterface|\Drupal\Core\Entity\EntityPublishedInterface $entity */
  // Track the sequence of revisions created for this entity.
  $sequence_key = $entity->getEntityTypeId() . '.' . $entity->uuid() . '.revision_sequence';
  $sequence = $this->keyValueFactory
    ->get('ws_test')
    ->get($sequence_key, []);
  $sequence[] = [
    'is_new' => $entity->isNew(),
    'is_new_revision' => $entity->isNewRevision(),
    'is_published' => $entity->isPublished(),
    'is_default_revision' => $entity->isDefaultRevision(),
  ];
  $this->keyValueFactory
    ->get('ws_test')
    ->set($sequence_key, $sequence);
}

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