diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigDependencyDeleteForm.php b/core/lib/Drupal/Core/Config/Entity/ConfigDependencyDeleteFormTrait.php similarity index 79% rename from core/lib/Drupal/Core/Config/Entity/ConfigDependencyDeleteForm.php rename to core/lib/Drupal/Core/Config/Entity/ConfigDependencyDeleteFormTrait.php index 7630413..ada9ac3 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigDependencyDeleteForm.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigDependencyDeleteFormTrait.php @@ -2,20 +2,21 @@ /** * @file - * Contains \Drupal\Core\Config\Entity\ConfigDependencyDeleteForm; + * Contains \Drupal\Core\Config\Entity\ConfigDependencyDeleteFormTrait; */ namespace Drupal\Core\Config\Entity; +use Drupal\Core\Config\ConfigManagerInterface; use Drupal\Core\Entity\EntityManagerInterface; /** - * Lists affected configuration entities during a during a dependency removal. + * Lists affected configuration entities by a dependency removal. * * This trait relies on the StringTranslationTrait. */ -trait ConfigDependencyDeleteForm { +trait ConfigDependencyDeleteFormTrait { /** * Translates a string to the current language or to a given language. @@ -29,13 +30,23 @@ * * @param array $form * The form array to add elements to. - * @param array $dependent_entities - * The list of dependent entities from + * @param string $type + * The type of dependency being checked. Either 'module', 'theme', 'config' + * or 'content'. + * @param array $names + * The specific names to check. If $type equals 'module' or 'theme' then it + * should be a list of module names or theme names. In the case of 'config' + * or 'content' it should be a list of configuration dependency names. + * @param \Drupal\Core\Config\ConfigManagerInterface $config_manager + * The config manager. * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager * The entity manager. + * + * @see \Drupal\Core\Config\ConfigManagerInterface::getConfigEntitiesToChangeOnDependencyRemoval() */ - protected function addDependencyListsToForm(array &$form, array $dependent_entities, EntityManagerInterface $entity_manager) { + protected function addDependencyListsToForm(array &$form, $type, array $names, ConfigManagerInterface $config_manager, EntityManagerInterface $entity_manager) { // Get the dependent entities. + $dependent_entities = $config_manager->getConfigEntitiesToChangeOnDependencyRemoval($type, $names); $entity_types = array(); $form['entity_updates'] = array( diff --git a/core/lib/Drupal/Core/Entity/EntityDeleteForm.php b/core/lib/Drupal/Core/Entity/EntityDeleteForm.php index 76aa3cf..7869af8 100644 --- a/core/lib/Drupal/Core/Entity/EntityDeleteForm.php +++ b/core/lib/Drupal/Core/Entity/EntityDeleteForm.php @@ -6,6 +6,7 @@ */ namespace Drupal\Core\Entity; + use Drupal\Core\Config\Entity\ConfigEntityInterface; use Drupal\Core\Form\FormStateInterface; @@ -32,9 +33,19 @@ public function buildForm(array $form, FormStateInterface $form_state) { if (!($entity instanceof ConfigEntityInterface)) { return $form; } - $dependent_entities = \Drupal::service('config.manager')->getConfigEntitiesToChangeOnDependencyRemoval($entity->getConfigDependencyKey(), [$entity->getConfigDependencyName()]); - $this->addDependencyListsToForm($form, $dependent_entities, $this->entityManager); + $this->addDependencyListsToForm($form, $entity->getConfigDependencyKey(), [$entity->getConfigDependencyName()], $this->getConfigManager(), $this->entityManager); return $form; } + + /** + * Gets the configuration manager. + * + * @return \Drupal\Core\Config\ConfigManager + * The configuration manager. + */ + protected function getConfigManager() { + return \Drupal::service('config.manager'); + } + } diff --git a/core/lib/Drupal/Core/Entity/EntityDeleteFormTrait.php b/core/lib/Drupal/Core/Entity/EntityDeleteFormTrait.php index c14cb75..7e4ce04 100644 --- a/core/lib/Drupal/Core/Entity/EntityDeleteFormTrait.php +++ b/core/lib/Drupal/Core/Entity/EntityDeleteFormTrait.php @@ -7,7 +7,7 @@ namespace Drupal\Core\Entity; -use Drupal\Core\Config\Entity\ConfigDependencyDeleteForm; +use Drupal\Core\Config\Entity\ConfigDependencyDeleteFormTrait; use Drupal\Core\Form\FormStateInterface; /** @@ -19,7 +19,7 @@ * @ingroup entity_api */ trait EntityDeleteFormTrait { - use ConfigDependencyDeleteForm; + use ConfigDependencyDeleteFormTrait; /** * Returns the entity of this form. diff --git a/core/modules/field/src/Entity/FieldStorageConfig.php b/core/modules/field/src/Entity/FieldStorageConfig.php index 7d66b53..a1c2d58 100644 --- a/core/modules/field/src/Entity/FieldStorageConfig.php +++ b/core/modules/field/src/Entity/FieldStorageConfig.php @@ -384,7 +384,7 @@ public static function preDelete(EntityStorageInterface $storage, array $field_s // Set the static flag so that we don't delete field storages whilst // deleting fields. - self::$inDeletion = TRUE; + static::$inDeletion = TRUE; // Delete or fix any configuration that is dependent, for example, fields. parent::preDelete($storage, $field_storages); @@ -416,7 +416,7 @@ public static function postDelete(EntityStorageInterface $storage, array $fields } } // Unset static flag. - self::$inDeletion = FALSE; + static::$inDeletion = FALSE; } /** @@ -789,7 +789,7 @@ public function isDeletable() { // The field storage is not deleted, is configured to be removed when there // are no fields, the field storage has no bundles, and field storages are // not in the process of being deleted. - return !$this->deleted && !$this->persist_with_no_fields && count($this->getBundles()) == 0 && !self::$inDeletion; + return !$this->deleted && !$this->persist_with_no_fields && count($this->getBundles()) == 0 && !static::$inDeletion; } /** diff --git a/core/modules/system/src/Form/ModulesUninstallConfirmForm.php b/core/modules/system/src/Form/ModulesUninstallConfirmForm.php index fe7515c..159959d 100644 --- a/core/modules/system/src/Form/ModulesUninstallConfirmForm.php +++ b/core/modules/system/src/Form/ModulesUninstallConfirmForm.php @@ -8,7 +8,7 @@ namespace Drupal\system\Form; use Drupal\Core\Config\ConfigManagerInterface; -use Drupal\Core\Config\Entity\ConfigDependencyDeleteForm; +use Drupal\Core\Config\Entity\ConfigDependencyDeleteFormTrait; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Extension\ModuleInstallerInterface; use Drupal\Core\Form\ConfirmFormBase; @@ -22,7 +22,7 @@ * Builds a confirmation form to uninstall selected modules. */ class ModulesUninstallConfirmForm extends ConfirmFormBase { - use ConfigDependencyDeleteForm; + use ConfigDependencyDeleteFormTrait; /** * The module installer service. @@ -148,8 +148,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { ); // List the dependent entities. - $dependent_entities = $this->configManager->getConfigEntitiesToChangeOnDependencyRemoval('module', $this->modules); - $this->addDependencyListsToForm($form, $dependent_entities, $this->entityManager); + $this->addDependencyListsToForm($form, 'module', $this->modules ,$this->configManager, $this->entityManager); return parent::buildForm($form, $form_state); }