diff --git a/core/modules/field_ui/src/Tests/FieldUIDeleteTest.php b/core/modules/field_ui/src/Tests/FieldUIDeleteTest.php index e6e2f59..269a698 100644 --- a/core/modules/field_ui/src/Tests/FieldUIDeleteTest.php +++ b/core/modules/field_ui/src/Tests/FieldUIDeleteTest.php @@ -96,13 +96,12 @@ function testDeleteField() { // Check the config dependencies of the first field. $this->drupalGet("$bundle_path2/fields/node.$type_name2.$field_name/delete"); - $this->assertText(t('The listed configuration will be deleted.')); + $this->assertText(t('The listed configuration will be updated.')); $this->assertText(t('View')); $this->assertText('test_view_field_delete'); - $xml = $this->cssSelect('#edit-entity-deletes'); - // Remove the wrapping HTML. - $this->assertIdentical(FALSE, strpos($xml[0]->asXml(), $field_label), 'The currently being deleted field is not shown in the entity deletions.'); + // There are no dependency deletes. + $this->assertTrue(empty($this->cssSelect('#edit-entity-deletes')), 'The currently being deleted field is not shown in the entity.'); // Delete the second field. $this->fieldUIDeleteField($bundle_path2, "node.$type_name2.$field_name", $field_label, $type_name2); diff --git a/core/modules/views/src/Entity/View.php b/core/modules/views/src/Entity/View.php index 1ae933d..bf0a4a5 100644 --- a/core/modules/views/src/Entity/View.php +++ b/core/modules/views/src/Entity/View.php @@ -295,17 +295,44 @@ public function calculateDependencies() { public function onDependencyRemoval(array $dependencies) { $changed = parent::onDependencyRemoval($dependencies); + $types = Views::getHandlerTypes(); $executable = $this->getExecutable(); $executable->initDisplay(); $executable->initStyle(); - /** @var \Drupal\Component\Plugin\DependentPluginInterface $display */ + /** @var \Drupal\views\Plugin\views\display\DisplayPluginInterface $display */ foreach ($executable->displayHandlers as $display_id => &$display) { $display_removed_dependencies = $this->getPluginRemovedDependencies($display->calculateDependencies(), $dependencies); - /** @var \Drupal\views\Plugin\views\ViewsHandlerDependencyInterface $display */ - if ($display_removed_dependencies && $display->onDependencyRemoval($display_removed_dependencies)) { - // The display was already updated. - $changed = TRUE; + if ($display_removed_dependencies) { + foreach ($display->handlers as $type => &$handlers) { + $option = $display->getOption($types[$type]['plural']); + /** @var \Drupal\views\Plugin\views\ViewsHandlerInterface $handler */ + foreach ($handlers as $handler_id => &$handler) { + $plugin_removed_dependencies = $this->getPluginRemovedDependencies($handler->calculateDependencies(), $dependencies); + if ($plugin_removed_dependencies) { + if ($handler->onDependencyRemoval($plugin_removed_dependencies)) { + // Update the handler. + $option[$handler_id] = $handler->options; + $changed = TRUE; + } + + // If there are still unresolved deleted dependencies left, remove + // this handler to avoid the removal of the entire view. + if ($this->getPluginRemovedDependencies($handler->calculateDependencies(), $dependencies)) { + unset($option[$handler_id], $display->handlers[$type][$handler_id]); + $arguments = [ + '@view' => $this->id(), + '@display' => $display->getPluginId(), + '@type' => $types[$type]['stitle'], + '@name' => $handler_id, + ]; + $this->getLogger()->warning("View '@view', display '@display': @type '@name' was removed because its settings depend on removed dependencies.", $arguments); + $changed = TRUE; + } + } + } + $display->setOption($types[$type]['plural'], $option); + } } } @@ -313,6 +340,16 @@ public function onDependencyRemoval(array $dependencies) { } /** + * Provides the 'views' channel logger service. + * + * @return \Psr\Log\LoggerInterface + * The 'views' channel logger. + */ + protected function getLogger() { + return \Drupal::logger('views'); + } + + /** * {@inheritdoc} */ public function preSave(EntityStorageInterface $storage) { diff --git a/core/modules/views/src/Plugin/views/HandlerBase.php b/core/modules/views/src/Plugin/views/HandlerBase.php index 7546fd4..b1fc93f 100644 --- a/core/modules/views/src/Plugin/views/HandlerBase.php +++ b/core/modules/views/src/Plugin/views/HandlerBase.php @@ -7,6 +7,7 @@ namespace Drupal\views\Plugin\views; +use Drupal\Component\Plugin\DependentPluginInterface; use Drupal\Component\Utility\Html; use Drupal\Component\Utility\Unicode; use Drupal\Component\Utility\UrlHelper; @@ -26,7 +27,7 @@ * * @ingroup views_plugins */ -abstract class HandlerBase extends PluginBase implements ViewsHandlerInterface, ViewsHandlerDependencyInterface { +abstract class HandlerBase extends PluginBase implements ViewsHandlerInterface, DependentPluginInterface { /** * Where the $query object will reside: diff --git a/core/modules/views/src/Plugin/views/ViewsHandlerDependencyInterface.php b/core/modules/views/src/Plugin/views/ViewsHandlerDependencyInterface.php deleted file mode 100644 index 7a3a48b..0000000 --- a/core/modules/views/src/Plugin/views/ViewsHandlerDependencyInterface.php +++ /dev/null @@ -1,36 +0,0 @@ -dependencies; } - /** - * {@inheritdoc} - */ - public function onDependencyRemoval(array $dependencies) { - $changed = FALSE; - - $types = Views::getHandlerTypes(); - foreach (array_keys($types) as $type) { - $option = $this->getOption($types[$type]['plural']); - /** @var \Drupal\Component\Plugin\DependentPluginInterface $handler */ - foreach ($this->getHandlers($type) as $handler_id => &$handler) { - $plugin_removed_dependencies = $this->getPluginRemovedDependencies($handler->calculateDependencies(), $dependencies); - if ($plugin_removed_dependencies) { - if ($handler->onDependencyRemoval($plugin_removed_dependencies)) { - // Update the handler. - $option[$handler_id] = $handler->options; - $changed = TRUE; - } - - // If there are still unresolved deleted dependencies left, remove - // this handler to avoid the removal of the entire view. - if ($this->getPluginRemovedDependencies($handler->calculateDependencies(), $dependencies)) { - unset($option[$handler_id], $this->handlers[$type][$handler_id]); - $arguments = [ - '@view' => $this->view->id(), - '@display' => $this->getPluginId(), - '@type' => $types[$type]['stitle'], - '@name' => $handler_id, - ]; - $this->getLogger()->warning("View '@view', display '@display': @type '@name' was removed because its settings depend on removed dependencies.", $arguments); - $changed = TRUE; - } - } - } - $this->setOption($types[$type]['plural'], $option); - } - - return $changed; - } - - /** - * Provides the 'views' channel logger service. - * - * @return \Psr\Log\LoggerInterface - * The 'views' channel logger. - */ - protected function getLogger() { - return \Drupal::logger('views'); - } /** * {@inheritdoc} diff --git a/core/modules/views/src/Plugin/views/field/Field.php b/core/modules/views/src/Plugin/views/field/Field.php index 2bb335d..7038b3b 100644 --- a/core/modules/views/src/Plugin/views/field/Field.php +++ b/core/modules/views/src/Plugin/views/field/Field.php @@ -13,7 +13,6 @@ use Drupal\Core\Cache\CacheableDependencyInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityManagerInterface; -use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Core\Field\FieldTypePluginManagerInterface; use Drupal\Core\Field\FormatterPluginManager; @@ -43,6 +42,7 @@ * @ViewsField("field") */ class Field extends FieldPluginBase implements CacheableDependencyInterface, MultiItemsFieldHandlerInterface { + use FieldAPIHandlerTrait; use PluginDependencyTrait;