diff --git a/core/lib/Drupal/Core/Config/ConfigManager.php b/core/lib/Drupal/Core/Config/ConfigManager.php index 7b3a74b..c7796c4 100644 --- a/core/lib/Drupal/Core/Config/ConfigManager.php +++ b/core/lib/Drupal/Core/Config/ConfigManager.php @@ -413,12 +413,12 @@ protected function callOnDependencyRemoval(ConfigEntityInterface $entity, array if ($type == 'config' || $type == 'content') { $affected_dependencies[$type] = array_map(function ($name) use ($type) { if ($type == 'config') { - $entity_type_id = $this->getEntityTypeIdByName($name); + return $this->loadConfigEntityByName($name); } else { list($entity_type_id) = explode(':', $name); + return $this->entityManager->loadEntityByConfigTarget($entity_type_id, $name); } - return $this->entityManager->loadEntityByConfigTarget($entity_type_id, $name); }, $affected_dependencies[$type]); } } diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigDependencyDeleteForm.php b/core/lib/Drupal/Core/Config/Entity/ConfigDependencyDeleteForm.php new file mode 100644 index 0000000..7630413 --- /dev/null +++ b/core/lib/Drupal/Core/Config/Entity/ConfigDependencyDeleteForm.php @@ -0,0 +1,119 @@ + 'details', + '#title' => $this->t('Configuration updates'), + '#description' => $this->t('The listed configuration will be updated.'), + '#collapsible' => TRUE, + '#collapsed' => TRUE, + '#access' => FALSE, + ); + + foreach ($dependent_entities['update'] as $entity) { + /** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $entity */ + $entity_type_id = $entity->getEntityTypeId(); + if (!isset($form['entity_updates'][$entity_type_id])) { + $entity_type = $entity_manager->getDefinition($entity_type_id); + // Store the ID and label to sort the entity types and entities later. + $label = $entity_type->getLabel(); + $entity_types[$entity_type_id] = $label; + $form['entity_updates'][$entity_type_id] = array( + '#theme' => 'item_list', + '#title' => $label, + '#items' => array(), + ); + } + $form['entity_updates'][$entity_type_id]['#items'][] = $entity->label() ?: $entity->id(); + } + if (!empty($dependent_entities['update'])) { + $form['entity_updates']['#access'] = TRUE; + + // Add a weight key to the entity type sections. + asort($entity_types, SORT_FLAG_CASE); + $weight = 0; + foreach ($entity_types as $entity_type_id => $label) { + $form['entity_updates'][$entity_type_id]['#weight'] = $weight; + // Sort the list of entity labels alphabetically. + sort($form['entity_updates'][$entity_type_id]['#items'], SORT_FLAG_CASE); + $weight++; + } + } + + $form['entity_deletes'] = array( + '#type' => 'details', + '#title' => $this->t('Configuration deletions'), + '#description' => $this->t('The listed configuration will be deleted.'), + '#collapsible' => TRUE, + '#collapsed' => TRUE, + '#access' => FALSE, + ); + + foreach ($dependent_entities['delete'] as $entity) { + $entity_type_id = $entity->getEntityTypeId(); + if (!isset($form['entity_deletes'][$entity_type_id])) { + $entity_type = $entity_manager->getDefinition($entity_type_id); + // Store the ID and label to sort the entity types and entities later. + $label = $entity_type->getLabel(); + $entity_types[$entity_type_id] = $label; + $form['entity_deletes'][$entity_type_id] = array( + '#theme' => 'item_list', + '#title' => $label, + '#items' => array(), + ); + } + $form['entity_deletes'][$entity_type_id]['#items'][] = $entity->label() ?: $entity->id(); + } + if (!empty($dependent_entities['delete'])) { + $form['entity_deletes']['#access'] = TRUE; + + // Add a weight key to the entity type sections. + asort($entity_types, SORT_FLAG_CASE); + $weight = 0; + foreach ($entity_types as $entity_type_id => $label) { + $form['entity_deletes'][$entity_type_id]['#weight'] = $weight; + // Sort the list of entity labels alphabetically. + sort($form['entity_deletes'][$entity_type_id]['#items'], SORT_FLAG_CASE); + $weight++; + } + } + + } +} diff --git a/core/lib/Drupal/Core/Entity/EntityDeleteForm.php b/core/lib/Drupal/Core/Entity/EntityDeleteForm.php index 1bd9d8e..76aa3cf 100644 --- a/core/lib/Drupal/Core/Entity/EntityDeleteForm.php +++ b/core/lib/Drupal/Core/Entity/EntityDeleteForm.php @@ -15,7 +15,6 @@ * @ingroup entity_api */ class EntityDeleteForm extends EntityConfirmFormBase { - use EntityDeleteFormTrait; /** @@ -33,45 +32,8 @@ public function buildForm(array $form, FormStateInterface $form_state) { if (!($entity instanceof ConfigEntityInterface)) { return $form; } - $dependent_entities = \Drupal::service('config.manager')->findConfigEntityDependentsAsEntities($entity->getConfigDependencyKey(), [$entity->getConfigDependencyName()]); - - $form['other_entities'] = array( - '#type' => 'details', - '#title' => $this->t('Affected configuration'), - '#description' => $this->t('The listed configuration will be updated if possible, or deleted.'), - '#collapsible' => TRUE, - '#collapsed' => TRUE, - '#access' => FALSE, - ); - foreach ($dependent_entities as $dependent_entity) { - $entity_type_id = $dependent_entity->getEntityTypeId(); - if (!isset($form['entities'][$entity_type_id])) { - $entity_type = $this->entityManager->getDefinition($entity_type_id); - // Store the ID and label to sort the dependent_entity types and - // entities later. - $label = $entity_type->getLabel(); - $entity_types[$entity_type_id] = $label; - $form['other_entities'][$entity_type_id] = array( - '#theme' => 'item_list', - '#title' => $label, - '#items' => array(), - ); - } - $form['other_entities'][$entity_type_id]['#items'][] = $dependent_entity->label() ?: $dependent_entity->id(); - } - if (!empty($dependent_entities)) { - $form['other_entities']['#access'] = TRUE; - - // Add a weight key to the dependent entity type sections. - asort($entity_types, SORT_FLAG_CASE); - $weight = 0; - foreach ($entity_types as $entity_type_id => $label) { - $form['other_entities'][$entity_type_id]['#weight'] = $weight; - // Sort the list of dependent_entity labels alphabetically. - sort($form['other_entities'][$entity_type_id]['#items'], SORT_FLAG_CASE); - $weight++; - } - } + $dependent_entities = \Drupal::service('config.manager')->getConfigEntitiesToChangeOnDependencyRemoval($entity->getConfigDependencyKey(), [$entity->getConfigDependencyName()]); + $this->addDependencyListsToForm($form, $dependent_entities, $this->entityManager); return $form; } diff --git a/core/lib/Drupal/Core/Entity/EntityDeleteFormTrait.php b/core/lib/Drupal/Core/Entity/EntityDeleteFormTrait.php index 80bb50d..c14cb75 100644 --- a/core/lib/Drupal/Core/Entity/EntityDeleteFormTrait.php +++ b/core/lib/Drupal/Core/Entity/EntityDeleteFormTrait.php @@ -7,6 +7,7 @@ namespace Drupal\Core\Entity; +use Drupal\Core\Config\Entity\ConfigDependencyDeleteForm; use Drupal\Core\Form\FormStateInterface; /** @@ -18,13 +19,7 @@ * @ingroup entity_api */ trait EntityDeleteFormTrait { - - /** - * Translates a string to the current language or to a given language. - * - * Provided by \Drupal\Core\StringTranslation\StringTranslationTrait. - */ - abstract protected function t($string, array $args = array(), array $options = array()); + use ConfigDependencyDeleteForm; /** * Returns the entity of this form. diff --git a/core/modules/field/field.module b/core/modules/field/field.module index d8be776..e4562a3 100644 --- a/core/modules/field/field.module +++ b/core/modules/field/field.module @@ -246,24 +246,6 @@ function field_entity_bundle_rename($entity_type, $bundle_old, $bundle_new) { } /** - * Implements hook_entity_bundle_delete(). - * - * This deletes the data for the field as well as the field themselves. This - * function actually just marks the data and fields as deleted, leaving the - * garbage collection for a separate process, because it is not always - * possible to delete this much data in a single page request (particularly - * since for some field types, the deletion is more than just a simple DELETE - * query). - */ -function field_entity_bundle_delete($entity_type, $bundle) { - // Get the fields on the bundle. - $fields = entity_load_multiple_by_properties('field_config', array('entity_type' => $entity_type, 'bundle' => $bundle)); - foreach ($fields as $field) { - $field->delete(); - } -} - -/** * @} End of "defgroup field". */ diff --git a/core/modules/language/language.module b/core/modules/language/language.module index 5b2099e..67356be 100644 --- a/core/modules/language/language.module +++ b/core/modules/language/language.module @@ -238,17 +238,6 @@ function language_entity_bundle_rename($entity_type_id, $bundle_old, $bundle_new } /** - * Implements hook_entity_bundle_delete(). - */ -function language_entity_bundle_delete($entity_type_id, $bundle) { - // Remove the content language settings associated with the bundle. - $settings = ContentLanguageSettings::loadByEntityTypeBundle($entity_type_id, $bundle); - if (!$settings->isNew()) { - $settings->delete(); - } -} - -/** * Returns the default language code assigned to an entity type and a bundle. * * @param string $entity_type diff --git a/core/modules/system/src/Form/ModulesUninstallConfirmForm.php b/core/modules/system/src/Form/ModulesUninstallConfirmForm.php index d6e5b15..fe7515c 100644 --- a/core/modules/system/src/Form/ModulesUninstallConfirmForm.php +++ b/core/modules/system/src/Form/ModulesUninstallConfirmForm.php @@ -8,6 +8,7 @@ namespace Drupal\system\Form; use Drupal\Core\Config\ConfigManagerInterface; +use Drupal\Core\Config\Entity\ConfigDependencyDeleteForm; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Extension\ModuleInstallerInterface; use Drupal\Core\Form\ConfirmFormBase; @@ -21,6 +22,7 @@ * Builds a confirmation form to uninstall selected modules. */ class ModulesUninstallConfirmForm extends ConfirmFormBase { + use ConfigDependencyDeleteForm; /** * The module installer service. @@ -145,86 +147,9 @@ public function buildForm(array $form, FormStateInterface $form_state) { }, $this->modules), ); - // Get the dependent entities. - $entity_types = array(); + // List the dependent entities. $dependent_entities = $this->configManager->getConfigEntitiesToChangeOnDependencyRemoval('module', $this->modules); - - $form['entity_updates'] = array( - '#type' => 'details', - '#title' => $this->t('Configuration updates'), - '#description' => $this->t('The listed configuration will be updated.'), - '#collapsible' => TRUE, - '#collapsed' => TRUE, - '#access' => FALSE, - ); - - foreach ($dependent_entities['update'] as $entity) { - /** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $entity */ - $entity_type_id = $entity->getEntityTypeId(); - if (!isset($form['entity_updates'][$entity_type_id])) { - $entity_type = $this->entityManager->getDefinition($entity_type_id); - // Store the ID and label to sort the entity types and entities later. - $label = $entity_type->getLabel(); - $entity_types[$entity_type_id] = $label; - $form['entity_updates'][$entity_type_id] = array( - '#theme' => 'item_list', - '#title' => $label, - '#items' => array(), - ); - } - $form['entity_updates'][$entity_type_id]['#items'][] = $entity->label() ?: $entity->id(); - } - if (!empty($dependent_entities['update'])) { - $form['entity_updates']['#access'] = TRUE; - - // Add a weight key to the entity type sections. - asort($entity_types, SORT_FLAG_CASE); - $weight = 0; - foreach ($entity_types as $entity_type_id => $label) { - $form['entity_updates'][$entity_type_id]['#weight'] = $weight; - // Sort the list of entity labels alphabetically. - sort($form['entity_updates'][$entity_type_id]['#items'], SORT_FLAG_CASE); - $weight++; - } - } - - $form['entity_deletes'] = array( - '#type' => 'details', - '#title' => $this->t('Configuration deletions'), - '#description' => $this->t('The listed configuration will be deleted.'), - '#collapsible' => TRUE, - '#collapsed' => TRUE, - '#access' => FALSE, - ); - - foreach ($dependent_entities['delete'] as $entity) { - $entity_type_id = $entity->getEntityTypeId(); - if (!isset($form['entity_deletes'][$entity_type_id])) { - $entity_type = $this->entityManager->getDefinition($entity_type_id); - // Store the ID and label to sort the entity types and entities later. - $label = $entity_type->getLabel(); - $entity_types[$entity_type_id] = $label; - $form['entity_deletes'][$entity_type_id] = array( - '#theme' => 'item_list', - '#title' => $label, - '#items' => array(), - ); - } - $form['entity_deletes'][$entity_type_id]['#items'][] = $entity->label() ?: $entity->id(); - } - if (!empty($dependent_entities['delete'])) { - $form['entity_deletes']['#access'] = TRUE; - - // Add a weight key to the entity type sections. - asort($entity_types, SORT_FLAG_CASE); - $weight = 0; - foreach ($entity_types as $entity_type_id => $label) { - $form['entity_deletes'][$entity_type_id]['#weight'] = $weight; - // Sort the list of entity labels alphabetically. - sort($form['entity_deletes'][$entity_type_id]['#items'], SORT_FLAG_CASE); - $weight++; - } - } + $this->addDependencyListsToForm($form, $dependent_entities, $this->entityManager); return parent::buildForm($form, $form_state); }