You are here

public static function FieldStorageConfig::preDelete in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/field/src/Entity/FieldStorageConfig.php \Drupal\field\Entity\FieldStorageConfig::preDelete()

Acts on entities before they are deleted and before hooks are invoked.

Used before the entities are deleted and before invoking the delete hook.

Parameters

\Drupal\Core\Entity\EntityStorageInterface $storage: The entity storage object.

\Drupal\Core\Entity\EntityInterface[] $entities: An array of entities.

Overrides ConfigEntityBase::preDelete

File

core/modules/field/src/Entity/FieldStorageConfig.php, line 402
Contains \Drupal\field\Entity\FieldStorageConfig.

Class

FieldStorageConfig
Defines the Field storage configuration entity.

Namespace

Drupal\field\Entity

Code

public static function preDelete(EntityStorageInterface $storage, array $field_storages) {
  $state = \Drupal::state();

  // Set the static flag so that we don't delete field storages whilst
  // deleting fields.
  static::$inDeletion = TRUE;

  // Delete or fix any configuration that is dependent, for example, fields.
  parent::preDelete($storage, $field_storages);

  // Keep the field definitions in the state storage so we can use them later
  // during field_purge_batch().
  $deleted_storages = $state
    ->get('field.storage.deleted') ?: array();
  foreach ($field_storages as $field_storage) {
    if (!$field_storage->deleted) {
      $config = $field_storage
        ->toArray();
      $config['deleted'] = TRUE;
      $config['bundles'] = $field_storage
        ->getBundles();
      $deleted_storages[$field_storage
        ->uuid()] = $config;
    }
  }
  $state
    ->set('field.storage.deleted', $deleted_storages);
}