You are here

public function EntityTypeListener::onFieldableEntityTypeUpdate in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Entity/EntityTypeListener.php \Drupal\Core\Entity\EntityTypeListener::onFieldableEntityTypeUpdate()

Reacts to the update of a fieldable entity type.

Parameters

\Drupal\Core\Entity\EntityTypeInterface $entity_type: The updated entity type definition.

\Drupal\Core\Entity\EntityTypeInterface $original: The original entity type definition.

\Drupal\Core\Field\FieldStorageDefinitionInterface[] $field_storage_definitions: The updated field storage definitions, including possibly new ones.

\Drupal\Core\Field\FieldStorageDefinitionInterface[] $original_field_storage_definitions: The original field storage definitions.

array &$sandbox: (optional) A sandbox array provided by a hook_update_N() implementation or a Batch API callback. If the entity schema update requires a data migration, this parameter is mandatory. Defaults to NULL.

Overrides EntityTypeListenerInterface::onFieldableEntityTypeUpdate

File

core/lib/Drupal/Core/Entity/EntityTypeListener.php, line 152

Class

EntityTypeListener
Reacts to entity type CRUD on behalf of the Entity system.

Namespace

Drupal\Core\Entity

Code

public function onFieldableEntityTypeUpdate(EntityTypeInterface $entity_type, EntityTypeInterface $original, array $field_storage_definitions, array $original_field_storage_definitions, array &$sandbox = NULL) {
  $entity_type_id = $entity_type
    ->id();

  // @todo Forward this to all interested handlers, not only storage, once
  //   iterating handlers is possible: https://www.drupal.org/node/2332857.
  $storage = $this->entityTypeManager
    ->createHandlerInstance($entity_type
    ->getStorageClass(), $entity_type);
  if ($storage instanceof EntityTypeListenerInterface) {
    $storage
      ->onFieldableEntityTypeUpdate($entity_type, $original, $field_storage_definitions, $original_field_storage_definitions, $sandbox);
  }
  if ($sandbox === NULL || isset($sandbox['#finished']) && $sandbox['#finished'] == 1) {
    $this->entityLastInstalledSchemaRepository
      ->setLastInstalledDefinition($entity_type);
    if ($entity_type
      ->entityClassImplements(FieldableEntityInterface::class)) {
      $this->entityLastInstalledSchemaRepository
        ->setLastInstalledFieldStorageDefinitions($entity_type_id, $field_storage_definitions);
    }
    $this->eventDispatcher
      ->dispatch(EntityTypeEvents::UPDATE, new EntityTypeEvent($entity_type, $original));
    $this
      ->clearCachedDefinitions();
  }
}