function FieldConfig::postDelete

Same name in other branches
  1. 9 core/modules/field/src/Entity/FieldConfig.php \Drupal\field\Entity\FieldConfig::postDelete()
  2. 8.9.x core/modules/field/src/Entity/FieldConfig.php \Drupal\field\Entity\FieldConfig::postDelete()
  3. 10 core/modules/field/src/Entity/FieldConfig.php \Drupal\field\Entity\FieldConfig::postDelete()

Overrides FieldConfigBase::postDelete

File

core/modules/field/src/Entity/FieldConfig.php, line 235

Class

FieldConfig
Defines the Field entity.

Namespace

Drupal\field\Entity

Code

public static function postDelete(EntityStorageInterface $storage, array $fields) {
    parent::postDelete($storage, $fields);
    // If this is part of a configuration synchronization then the following
    // configuration updates are not necessary.
    $entity = reset($fields);
    if ($entity->isSyncing()) {
        return;
    }
    // Delete the associated field storages if they are not used anymore and are
    // not persistent.
    $storages_to_delete = [];
    foreach ($fields as $field) {
        $storage_definition = $field->getFieldStorageDefinition();
        if (!$field->deleted && !$field->isUninstalling() && $storage_definition->isDeletable()) {
            // Key by field UUID to avoid deleting the same storage twice.
            $storages_to_delete[$storage_definition->uuid()] = $storage_definition;
        }
    }
    if ($storages_to_delete) {
        \Drupal::entityTypeManager()->getStorage('field_storage_config')
            ->delete($storages_to_delete);
    }
}

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