You are here

public function EntityTestDefinitionSubscriber::onFieldStorageDefinitionUpdate in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/system/tests/modules/entity_test/src/EntityTestDefinitionSubscriber.php \Drupal\entity_test\EntityTestDefinitionSubscriber::onFieldStorageDefinitionUpdate()

Reacts to the update of a field storage definition.

Parameters

\Drupal\Core\Field\FieldStorageDefinitionInterface $storage_definition: The field being updated.

\Drupal\Core\Field\FieldStorageDefinitionInterface $original: The original storage definition; i.e., the definition before the update.

Throws

\Drupal\Core\Entity\Exception\FieldStorageDefinitionUpdateForbiddenException Thrown when the update to the field is forbidden.

Overrides FieldStorageDefinitionEventSubscriberTrait::onFieldStorageDefinitionUpdate

File

core/modules/system/tests/modules/entity_test/src/EntityTestDefinitionSubscriber.php, line 177

Class

EntityTestDefinitionSubscriber
Test entity type and field storage definition event subscriber.

Namespace

Drupal\entity_test

Code

public function onFieldStorageDefinitionUpdate(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original) {
  $last_installed_definition = $this->entityLastInstalledSchemaRepository
    ->getLastInstalledFieldStorageDefinitions($storage_definition
    ->getTargetEntityTypeId())[$storage_definition
    ->getName()];
  if ((string) $last_installed_definition
    ->getLabel() === 'Updated field storage test') {
    $this
      ->storeDefinitionUpdate(FieldStorageDefinitionEvents::UPDATE);
  }
  $this
    ->storeEvent(FieldStorageDefinitionEvents::UPDATE);

  // Retrieve the live field storage definitions in order to warm the static
  // cache and then insert the new storage definition, so we can test that the
  // cache doesn't get stale after the event has fired.
  if ($this->updateLiveDefinitions) {
    $this->entityFieldManager
      ->getFieldStorageDefinitions($storage_definition
      ->getTargetEntityTypeId());
    $this->state
      ->set('entity_test_rev.additional_base_field_definitions', [
      $storage_definition
        ->getName() => $storage_definition,
    ]);
  }
}