diff -u b/core/modules/views/src/Entity/View.php b/core/modules/views/src/Entity/View.php --- b/core/modules/views/src/Entity/View.php +++ b/core/modules/views/src/Entity/View.php @@ -532,6 +532,8 @@ // Disable the View if we made no changes or the handlers were not able to // remove the dependencies. This will cause all handler dependencies to be // ignored on dependency calculation. + // @todo Display a message or add a 'disabled' fieldset that shows any + // disabled config. if ($disable) { $this->disable(); $arguments = [ diff -u b/core/modules/views/src/Plugin/views/field/EntityField.php b/core/modules/views/src/Plugin/views/field/EntityField.php --- b/core/modules/views/src/Plugin/views/field/EntityField.php +++ b/core/modules/views/src/Plugin/views/field/EntityField.php @@ -1075,11 +1075,19 @@ * {@inheritdoc} */ public function onDependencyRemoval(array $dependencies) { + // See if this handler is responsible for any of the dependencies being + // removed. If this is the case, indicate that this handler needs to be + // removed from the View. $remove = FALSE; + // Get all the current dependencies for this handler. $current_dependencies = $this->calculateDependencies(); foreach ($current_dependencies as $group => $dependency_list) { + // Check if any of the handler dependencies match the dependencies being + // removed. foreach ($dependency_list as $config_key) { if (isset($dependencies[$group]) && array_key_exists($config_key, $dependencies[$group])) { + // This handlers dependency matches a dependency being removed, + // indicate that this handler needs to be removed. $remove = TRUE; break 2; } only in patch2: unchanged: --- a/core/modules/field_ui/src/Tests/FieldUIDeleteTest.php +++ b/core/modules/field_ui/src/Tests/FieldUIDeleteTest.php @@ -91,13 +91,13 @@ 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.'); + // Test that nothing is scheduled for deletion. + $this->assertFalse(isset($xml[0]), 'The currently being deleted field is not shown in the entity deletions.'); // Delete the second field. $this->fieldUIDeleteField($bundle_path2, "node.$type_name2.$field_name", $field_label, $type_name2); only in patch2: unchanged: --- a/core/modules/views/tests/src/Kernel/ViewsConfigDependenciesIntegrationTest.php +++ b/core/modules/views/tests/src/Kernel/ViewsConfigDependenciesIntegrationTest.php @@ -5,6 +5,7 @@ use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldStorageConfig; use Drupal\image\Entity\ImageStyle; +use Drupal\user\Entity\Role; use Drupal\views\Entity\View; /** @@ -17,7 +18,7 @@ class ViewsConfigDependenciesIntegrationTest extends ViewsKernelTestBase { /** * {@inheritdoc} */ - public static $modules = ['field', 'file', 'image', 'entity_test']; + public static $modules = ['field', 'file', 'image', 'entity_test', 'user']; /** * {@inheritdoc} @@ -25,6 +26,15 @@ class ViewsConfigDependenciesIntegrationTest extends ViewsKernelTestBase { public static $testViews = ['entity_test_fields']; /** + * {@inheritdoc} + */ + protected function setUp($import_test_views = TRUE) { + parent::setUp($import_test_views); + + $this->installEntitySchema('user'); + } + + /** * Tests integration with image module. */ public function testImage() { @@ -69,8 +79,58 @@ public function testImage() { // Delete the 'foo' image style. $style->delete(); - // Checks that the view has been deleted too. - $this->assertNull(View::load('entity_test_fields')); + $view = View::load('entity_test_fields'); + + // Checks that the view has not been deleted too. + $this->assertNotNull(View::load('entity_test_fields')); + + // Checks that the image field was removed from the View. + $display = $view->getDisplay('default'); + $this->assertFalse(isset($display['display_options']['fields']['bar'])); + + } + + /** + * Tests removing a config dependency that disables the View. + */ + public function testConfigRemovalDisable() { + // Create a role we can add to the View and delete. + $role = Role::create(array( + 'id' => 'dummy', + 'label' => 'dummy', + )); + + $role->save(); + + /** @var \Drupal\views\ViewEntityInterface $view */ + $view = View::load('entity_test_fields'); + $display =& $view->getDisplay('default'); + + // Set the access to be restricted by the dummy role. + $display['display_options']['access'] = [ + 'type' => 'role', + 'options' => [ + 'role' => [ + $role->id() => $role->id(), + ], + ], + ]; + $view->save(); + + // Check that the View now has a dependency on the Role. + $dependencies = $view->getDependencies() + ['config' => []]; + $this->assertTrue(in_array('user.role.dummy', $dependencies['config'])); + + // Delete the role. + $role->delete(); + + $view = View::load('entity_test_fields'); + + // Checks that the view has not been deleted too. + $this->assertNotNull($view); + + // Checks that the view has been disabled. + $this->assertFalse($view->status()); } }