summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2015-12-10 15:21:01 (GMT)
committerAlex Pott2015-12-10 15:21:01 (GMT)
commitb6b7891ede23cde60f42c265d697fbe08779d158 (patch)
treef082afe9fbe525e6fe219b90eae31181b9cde71e
parent4706f543592c48cc744a58048b160c1810994653 (diff)
Issue #2596345 by mbovan, Nitesh Pawar, Shreya Shetty, dawehner: Deleting a view should rebuild the routes
-rw-r--r--core/modules/views/views.module16
-rw-r--r--core/modules/views_ui/src/Tests/DefaultViewsTest.php17
2 files changed, 33 insertions, 0 deletions
diff --git a/core/modules/views/views.module b/core/modules/views/views.module
index 47f9644..0faa5bb 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 84496ee..21be366 100644
--- a/core/modules/views_ui/src/Tests/DefaultViewsTest.php
+++ b/core/modules/views_ui/src/Tests/DefaultViewsTest.php
@@ -142,6 +142,23 @@ class DefaultViewsTest extends UITestBase {
$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');
}
/**