diff --git a/core/modules/views/views.module b/core/modules/views/views.module index 47f96449949ae6e8bbd73314d9430a482f3b5f92..0faa5bbad75e8ceef6f7181e5366c0461ff6e6e5 100644 --- a/core/modules/views/views.module +++ b/core/modules/views/views.module @@ -8,6 +8,7 @@ use Drupal\Component\Utility\Html; use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Database\Query\AlterableInterface; +use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\Element; use Drupal\Core\Routing\RouteMatchInterface; @@ -804,3 +805,18 @@ function views_local_tasks_alter(&$local_tasks) { $local_task = ViewsLocalTask::create($container, 'views_view'); $local_task->alterLocalTasks($local_tasks); } + +/** + * Implements hook_ENTITY_TYPE_delete(). + */ +function views_view_delete(EntityInterface $entity) { + // Rebuild the routes in case there is a routed display. + $executable = Views::executableFactory()->get($entity); + $executable->initDisplay(); + foreach ($executable->displayHandlers as $display) { + if ($display->getRoutedDisplay()) { + \Drupal::service('router.builder')->setRebuildNeeded(); + break; + } + } +} diff --git a/core/modules/views_ui/src/Tests/DefaultViewsTest.php b/core/modules/views_ui/src/Tests/DefaultViewsTest.php index 84496ee0388b95db6b6e18eeafacb80f7c6cd19f..21be366379ec782858983f406c7d11be5dd1ba7a 100644 --- a/core/modules/views_ui/src/Tests/DefaultViewsTest.php +++ b/core/modules/views_ui/src/Tests/DefaultViewsTest.php @@ -142,6 +142,23 @@ function testDefaultViews() { $this->drupalGet($edit_href); $this->assertResponse(404); $this->assertText('Page not found'); + + // Delete all duplicated Glossary views. + $this->drupalGet('admin/structure/views'); + $this->clickViewsOperationLink(t('Delete'), 'duplicate_of_glossary'); + // Submit the confirmation form. + $this->drupalPostForm(NULL, array(), t('Delete')); + + $this->drupalGet('glossary'); + $this->assertResponse(200); + + $this->drupalGet('admin/structure/views'); + $this->clickViewsOperationLink(t('Delete'), $random_name); + // Submit the confirmation form. + $this->drupalPostForm(NULL, array(), t('Delete')); + $this->drupalGet('glossary'); + $this->assertResponse(404); + $this->assertText('Page not found'); } /**