diff --git a/core/lib/Drupal/Core/Config/ConfigManager.php b/core/lib/Drupal/Core/Config/ConfigManager.php index f00fcd4..8ca0738 100644 --- a/core/lib/Drupal/Core/Config/ConfigManager.php +++ b/core/lib/Drupal/Core/Config/ConfigManager.php @@ -11,6 +11,7 @@ use Drupal\Core\Serialization\Yaml; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\TranslationInterface; +use Drupal\views\Entity\View; use Symfony\Component\EventDispatcher\EventDispatcherInterface; /** @@ -203,6 +204,11 @@ public function uninstall($type, $name) { $entity->delete(); } + foreach ($entities['disable'] as $entity) { + $entity->disable(); + $entity->save(); + } + $config_names = $this->configFactory->listAll($name . '.'); foreach ($config_names as $config_name) { $this->configFactory->getEditable($config_name)->delete(); @@ -297,12 +303,13 @@ public function getConfigEntitiesToChangeOnDependencyRemoval($type, array $names $dependency_manager = $this->getConfigDependencyManager(); $dependents = $this->findConfigEntityDependentsAsEntities($type, $names, $dependency_manager); $original_dependencies = $dependents; - $delete_uuids = $update_uuids = []; + $delete_uuids = $update_uuids = $disable_uuids = []; $return = [ 'update' => [], 'delete' => [], 'unchanged' => [], + 'disable' => [], ]; // Try to fix any dependencies and find out what will happen to the @@ -343,6 +350,16 @@ public function getConfigEntitiesToChangeOnDependencyRemoval($type, array $names $return['update'][] = $dependent; $update_uuids[] = $dependent->uuid(); } + else{ + if($dependent instanceof View) { + if($dependent->status() == 0) { + $return['disable'][] = $dependent; + $disable_uuids[] = $dependent->uuid(); + //$disable_uuids + $fixed = TRUE; + } + } + } } // If the entity cannot be fixed then it has to be deleted. if (!$fixed) { @@ -354,8 +371,8 @@ public function getConfigEntitiesToChangeOnDependencyRemoval($type, array $names } // Use the lists of UUIDs to filter the original list to work out which // configuration entities are unchanged. - $return['unchanged'] = array_filter($original_dependencies, function ($dependent) use ($delete_uuids, $update_uuids) { - return !(in_array($dependent->uuid(), $delete_uuids) || in_array($dependent->uuid(), $update_uuids)); + $return['unchanged'] = array_filter($original_dependencies, function ($dependent) use ($delete_uuids, $update_uuids, $disable_uuids) { + return !(in_array($dependent->uuid(), $delete_uuids) || in_array($dependent->uuid(), $update_uuids) || in_array($dependent->uuid(), $disable_uuids)); }); return $return; diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigDependencyDeleteFormTrait.php b/core/lib/Drupal/Core/Config/Entity/ConfigDependencyDeleteFormTrait.php index 44c02e3..19dbc6c 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigDependencyDeleteFormTrait.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigDependencyDeleteFormTrait.php @@ -81,6 +81,45 @@ protected function addDependencyListsToForm(array &$form, $type, array $names, C } } + $form['entity_disables'] = array( + '#type' => 'details', + '#title' => $this->t('Configuration deactivations'), + '#description' => $this->t('The listed configuration will be disabled.'), + '#open' => TRUE, + '#access' => FALSE, + ); + + foreach ($dependent_entities['disable'] as $entity) { + $entity_type_id = $entity->getEntityTypeId(); + if (!isset($form['entity_disables'][$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_disables'][$entity_type_id] = array( + '#theme' => 'item_list', + '#title' => $label, + '#items' => array(), + ); + } + $form['entity_disables'][$entity_type_id]['#items'][$entity->id()] = $entity->label() ?: $entity->id(); + } + if (!empty($dependent_entities['disable'])) { + $form['entity_disables']['#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) { + if (isset($form['entity_disables'][$entity_type_id])) { + $form['entity_disables'][$entity_type_id]['#weight'] = $weight; + // Sort the list of entity labels alphabetically. + ksort($form['entity_disables'][$entity_type_id]['#items'], SORT_FLAG_CASE); + $weight++; + } + } + } + $form['entity_deletes'] = array( '#type' => 'details', '#title' => $this->t('Configuration deletions'), diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php index 08e7e19..e7e065a 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php @@ -595,6 +595,11 @@ public static function preDelete(EntityStorageInterface $storage, array $entitie foreach ($config_entities['delete'] as $dependent_entity) { $dependent_entity->delete(); } + foreach ($config_entities['disable'] as $dependent_entity) { + $dependent_entity->disable(); + $dependent_entity->save(); + + } } } diff --git a/core/modules/views/src/Plugin/views/field/EntityField.php b/core/modules/views/src/Plugin/views/field/EntityField.php index 4c8032d..84504ff 100644 --- a/core/modules/views/src/Plugin/views/field/EntityField.php +++ b/core/modules/views/src/Plugin/views/field/EntityField.php @@ -20,8 +20,10 @@ use Drupal\Core\Render\RendererInterface; use Drupal\Core\Session\AccountInterface; use Drupal\Core\TypedData\TypedDataInterface; +use Drupal\field\Entity\FieldStorageConfig; use Drupal\views\FieldAPIHandlerTrait; use Drupal\views\Entity\Render\EntityFieldRenderer; +use Drupal\views\Plugin\DependentWithRemovalPluginInterface; use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\ResultRow; use Drupal\views\ViewExecutable; @@ -34,7 +36,7 @@ * * @ViewsField("field") */ -class EntityField extends FieldPluginBase implements CacheableDependencyInterface, MultiItemsFieldHandlerInterface { +class EntityField extends FieldPluginBase implements CacheableDependencyInterface, MultiItemsFieldHandlerInterface, DependentWithRemovalPluginInterface { use FieldAPIHandlerTrait; use PluginDependencyTrait; @@ -1070,4 +1072,21 @@ public function getValue(ResultRow $values, $field = NULL) { } } + /** + * {@inheritdoc} + */ + public function onDependencyRemoval(array $dependencies) + { + foreach ($dependencies['config'] as $field_storage){ + if($field_storage instanceof FieldStorageConfig){ + $storage = $this->getFieldStorageDefinition(); + if($field_storage->getTargetEntityTypeId() == $storage->getTargetEntityTypeId() && $field_storage->getName() == $storage->getName()){ + return TRUE; + } + } + } + return FALSE; + } + + }