FieldStorageConfig::preDelete

public static FieldStorageConfig::preDelete(EntityStorageInterface $storage, array $field_storages)

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 398

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);
}
doc_Drupal
2016-10-29 09:12:23
Comments
Leave a Comment

Please login to continue.