public static function ConfigImporterFieldPurger::getFieldStoragesToPurge in Drupal 9
Same name and namespace in other branches
- 8 core/modules/field/src/ConfigImporterFieldPurger.php \Drupal\field\ConfigImporterFieldPurger::getFieldStoragesToPurge()
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.
4 calls to ConfigImporterFieldPurger::getFieldStoragesToPurge()
- ConfigImporterFieldPurger::initializeSandbox in core/
modules/ field/ src/ ConfigImporterFieldPurger.php - Initializes the batch context sandbox for processing field deletions.
- ConfigImporterFieldPurger::process in core/
modules/ field/ src/ ConfigImporterFieldPurger.php - Processes fields targeted for purge as part of a configuration sync.
- field_config_import_steps_alter in core/
modules/ field/ field.module - Implements hook_config_import_steps_alter().
- field_form_config_admin_import_form_alter in core/
modules/ field/ field.module - Implements hook_form_FORM_ID_alter().
File
- core/
modules/ field/ src/ ConfigImporterFieldPurger.php, line 111
Class
- ConfigImporterFieldPurger
- Processes field purges before a configuration synchronization.
Namespace
Drupal\fieldCode
public static function getFieldStoragesToPurge(array $extensions, array $deletes) {
$providers = array_keys($extensions['module']);
$providers[] = 'core';
$storages_to_delete = [];
// Gather fields that will be deleted during configuration synchronization
// where the module that provides the field type is also being uninstalled.
$field_storage_ids = [];
foreach ($deletes as $config_name) {
$field_storage_config_prefix = \Drupal::entityTypeManager()
->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[] $deleted_storage_definitions */
$deleted_storage_definitions = \Drupal::service('entity_field.deleted_fields_repository')
->getFieldStorageDefinitions();
foreach ($deleted_storage_definitions as $field_storage_definition) {
if ($field_storage_definition instanceof FieldStorageConfigInterface && !in_array($field_storage_definition
->getTypeProvider(), $providers)) {
$storages_to_delete[$field_storage_definition
->id()] = $field_storage_definition;
}
}
return $storages_to_delete;
}