function EntitySchemaSubscriber::onEntityTypeUpdate

Same name in this branch
  1. 8.9.x core/modules/system/tests/modules/entity_test_update/src/EventSubscriber/EntitySchemaSubscriber.php \Drupal\entity_test_update\EventSubscriber\EntitySchemaSubscriber::onEntityTypeUpdate()
Same name in other branches
  1. 9 core/modules/workspaces/src/EventSubscriber/EntitySchemaSubscriber.php \Drupal\workspaces\EventSubscriber\EntitySchemaSubscriber::onEntityTypeUpdate()
  2. 9 core/modules/system/tests/modules/entity_test_update/src/EventSubscriber/EntitySchemaSubscriber.php \Drupal\entity_test_update\EventSubscriber\EntitySchemaSubscriber::onEntityTypeUpdate()
  3. 10 core/modules/workspaces/src/EventSubscriber/EntitySchemaSubscriber.php \Drupal\workspaces\EventSubscriber\EntitySchemaSubscriber::onEntityTypeUpdate()
  4. 10 core/modules/system/tests/modules/entity_test_update/src/EventSubscriber/EntitySchemaSubscriber.php \Drupal\entity_test_update\EventSubscriber\EntitySchemaSubscriber::onEntityTypeUpdate()
  5. 11.x core/modules/workspaces/src/EventSubscriber/EntitySchemaSubscriber.php \Drupal\workspaces\EventSubscriber\EntitySchemaSubscriber::onEntityTypeUpdate()
  6. 11.x core/modules/system/tests/modules/entity_test_update/src/EventSubscriber/EntitySchemaSubscriber.php \Drupal\entity_test_update\EventSubscriber\EntitySchemaSubscriber::onEntityTypeUpdate()

Overrides EntityTypeEventSubscriberTrait::onEntityTypeUpdate

1 call to EntitySchemaSubscriber::onEntityTypeUpdate()
EntitySchemaSubscriber::onFieldableEntityTypeUpdate in core/modules/workspaces/src/EventSubscriber/EntitySchemaSubscriber.php
Reacts to the update of a fieldable entity type.

File

core/modules/workspaces/src/EventSubscriber/EntitySchemaSubscriber.php, line 88

Class

EntitySchemaSubscriber
Defines a class for listening to entity schema changes.

Namespace

Drupal\workspaces\EventSubscriber

Code

public function onEntityTypeUpdate(EntityTypeInterface $entity_type, EntityTypeInterface $original) {
    // If the entity type is now supported by Workspaces, add the revision
    // metadata field.
    if ($this->workspaceManager
        ->isEntityTypeSupported($entity_type) && !$this->workspaceManager
        ->isEntityTypeSupported($original)) {
        $this->addRevisionMetadataField($entity_type);
    }
    // If the entity type is no longer supported by Workspaces, remove the
    // revision metadata field.
    if ($this->workspaceManager
        ->isEntityTypeSupported($original) && !$this->workspaceManager
        ->isEntityTypeSupported($entity_type)) {
        $revision_metadata_keys = $original->get('revision_metadata_keys');
        $field_storage_definition = $this->entityLastInstalledSchemaRepository
            ->getLastInstalledFieldStorageDefinitions($entity_type->id())[$revision_metadata_keys['workspace']];
        $this->entityDefinitionUpdateManager
            ->uninstallFieldStorageDefinition($field_storage_definition);
        // We are only removing a revision metadata key so we don't need to go
        // through the entity update process.
        $entity_type->setRevisionMetadataKey('workspace', NULL);
        $this->entityLastInstalledSchemaRepository
            ->setLastInstalledDefinition($entity_type);
    }
}

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