ConfigImporterFieldPurger::getFieldStoragesToPurge

public static ConfigImporterFieldPurger::getFieldStoragesToPurge(array $extensions, array $deletes)

Gets the list of fields to purge before configuration synchronization.

If, during a configuration synchronization, a field is being deleted and the module that provides the field type is being uninstalled then the field data must be purged before the module is uninstalled. Also, if deleted fields exist whose field types are provided by modules that are being uninstalled their data need to be purged too.

Parameters

array $extensions: The list of extensions that will be enabled after the configuration synchronization has finished.

array $deletes: The configuration that will be deleted by the configuration synchronization.

Return value

\Drupal\field\Entity\FieldStorageConfig[] An array of field storages that need purging before configuration can be synchronized.

File

core/modules/field/src/ConfigImporterFieldPurger.php, line 111

Class

ConfigImporterFieldPurger
Processes field purges before a configuration synchronization.

Namespace

Drupal\field

Code

public static function getFieldStoragesToPurge(array $extensions, array $deletes) {
  $providers = array_keys($extensions['module']);
  $providers[] = 'core';
  $storages_to_delete = array();

  // Gather fields that will be deleted during configuration synchronization
  // where the module that provides the field type is also being uninstalled.
  $field_storage_ids = array();
  foreach ($deletes as $config_name) {
    $field_storage_config_prefix = \Drupal::entityManager()->getDefinition('field_storage_config')->getConfigPrefix();
    if (strpos($config_name, $field_storage_config_prefix . '.') === 0) {
      $field_storage_ids[] = ConfigEntityStorage::getIDFromConfigName($config_name, $field_storage_config_prefix);
    }
  }
  if (!empty($field_storage_ids)) {
    $field_storages = \Drupal::entityQuery('field_storage_config')
      ->condition('id', $field_storage_ids, 'IN')
      ->condition('module', $providers, 'NOT IN')
      ->execute();
    if (!empty($field_storages)) {
      $storages_to_delete = FieldStorageConfig::loadMultiple($field_storages);
    }
  }

  // Gather deleted fields from modules that are being uninstalled.
  /** @var \Drupal\field\FieldStorageConfigInterface[] $field_storages */
  $field_storages = entity_load_multiple_by_properties('field_storage_config', array('deleted' => TRUE, 'include_deleted' => TRUE));
  foreach ($field_storages as $field_storage) {
    if (!in_array($field_storage->getTypeProvider(), $providers)) {
      $storages_to_delete[$field_storage->id()] = $field_storage;
    }
  }
  return $storages_to_delete;
}
doc_Drupal
2016-10-29 08:53:44
Comments
Leave a Comment

Please login to continue.