diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php index 957c4e9..45e3fe8 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php @@ -454,10 +454,13 @@ protected static function invalidateTagsOnDelete(EntityTypeInterface $entity_typ Cache::invalidateTags($entity_type->getListCacheTags()); } + /** + * {@inheritdoc} + */ public static function preDelete(EntityStorageInterface $storage, array $entities) { foreach ($entities as $entity) { if ($entity->isUninstalling() || $entity->isSyncing()) { - // During extension uninstall and configuration synchronisation + // During extension uninstall and configuration synchronization // deletions are already managed. break; } @@ -471,9 +474,6 @@ public static function preDelete(EntityStorageInterface $storage, array $entitie 'module' => [], 'theme' => [] ]; - // Because we are only passing in one dependency to the - // onDependencyRemoval method returns TRUE then we assume that the - // dependency has been removed. if (!$dependent->onDependencyRemoval($dependencies_for_removal)) { $dependent->delete(); } @@ -483,5 +483,4 @@ public static function preDelete(EntityStorageInterface $storage, array $entitie parent::preDelete($storage, $entities); } - } diff --git a/core/lib/Drupal/Core/Entity/EntityDeleteForm.php b/core/lib/Drupal/Core/Entity/EntityDeleteForm.php index 257a853..93c1c13 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; /** @@ -23,6 +24,14 @@ class EntityDeleteForm extends EntityConfirmFormBase { public function buildForm(array $form, FormStateInterface $form_state) { $form = parent::buildForm($form, $form_state); $entity = $this->getEntity(); + // Only do dependency processing for configuration entities. Whilst it is + // possible for a configuration entity to be dependent on a content entity, + // these dependencies are soft and content delete permissions are often + // given to more users. The in this method should not make assumptions that + // $entity is a configuration entity in case we decide to change this later. + if (!($entity instanceof ConfigEntityInterface)) { + return $form; + } $dependent_entities = \Drupal::service('config.manager')->findConfigEntityDependentsAsEntities($entity->getConfigDependencyKey(), [$entity->getConfigDependencyName()]); $form['other_entities'] = array( @@ -37,7 +46,8 @@ public function buildForm(array $form, FormStateInterface $form_state) { $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. + // 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( @@ -51,7 +61,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { if (!empty($dependent_entities)) { $form['other_entities']['#access'] = TRUE; - // Add a weight key to the dependent_entity type sections. + // 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) { diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php index e45aae7..10497ad 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php @@ -286,6 +286,9 @@ public static function calculateDependencies(FieldDefinitionInterface $field_def return $dependencies; } + /** + * {@inheritdoc} + */ public static function onDependencyRemoval(FieldDefinitionInterface $field_definition, array $dependencies) { $changed = FALSE; if (is_array($field_definition->default_value) && count($field_definition->default_value)) { diff --git a/core/modules/field/src/Entity/FieldStorageConfig.php b/core/modules/field/src/Entity/FieldStorageConfig.php index 203b961..02fbd0f 100644 --- a/core/modules/field/src/Entity/FieldStorageConfig.php +++ b/core/modules/field/src/Entity/FieldStorageConfig.php @@ -202,7 +202,7 @@ class FieldStorageConfig extends ConfigEntityBase implements FieldStorageConfigI * * @var bool */ - protected static $in_deletion = FALSE; + protected static $inDeletion = FALSE; /** * Constructs a FieldStorageConfig object. @@ -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::$in_deletion = TRUE; + self::$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::$in_deletion = FALSE; + self::$inDeletion = FALSE; } /** @@ -739,8 +739,9 @@ public static function loadByName($entity_type_id, $field_name) { */ public function isDeletable() { // The field storage is not deleted, is configured to be removed when there - // are no fields and the field storage has no bundles. - return !$this->deleted && !$this->persist_with_no_fields && count($this->getBundles()) == 0 && !self::$in_deletion; + // 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; } }