Problem/Motivation

Steps to reproduce:

  1. Login to Drupal 8 administration
  2. Go to Structure > Views (admin/structure/views)
  3. Enable Glossary view
  4. Go to /glossary
  5. Delete Glossary view
  6. Go to /glossary link tab and reload your tab.
  7. Fatal error: Unsupported operand types in .../core/modules/views/src/Element/View.php on line 54

The problem disappears after clearing the cache.

Proposed resolution

As stated in the title, deleting a view should rebuild the routes...

Remaining tasks

User interface changes

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mbovan created an issue. See original summary.

lhuria94’s picture

Hi

Followed your steps to generate the issue:
On Drupal 8.0.0-dev, I am not able to generate it.

Thoughts?

lhuria94’s picture

Nitesh Pawar’s picture

Status: Active » Needs work
FileSize
186.75 KB

Actually we need to clear cache programetically after deletion of any view.
@lhuria94 - Please follow below steps.
1. Open /glossary in new tab.
2. Delete Glossary view.
3. Go to /glossary link tab and reload your tab.

lhuria94’s picture

okay, I checked again.
Its shows WSOD on the page when I go to /glossary link after the deletion of the view.

Nitesh Pawar’s picture

Status: Needs work » Needs review
FileSize
447 bytes
mbovan’s picture

Issue summary: View changes

@lhuria94, missed the reload step in the issue summary. Changed now.
@Nitesh Pawar, thanks for clarifying. :)

Status: Needs review » Needs work

The last submitted patch, 6: 2596345-6.patch, failed testing.

dawehner’s picture

+++ b/core/modules/views/src/Entity/View.php
@@ -423,6 +423,7 @@ public static function postDelete(EntityStorageInterface $storage, array $entiti
+    drupal_flush_all_caches();

Isn't it enough to call \Drupal::service('router.builder')->setRebuildNeeded(); ?

Shreya Shetty’s picture

Assigned: Unassigned » Shreya Shetty
Shreya Shetty’s picture

Assigned: Shreya Shetty » Unassigned
FileSize
477 bytes

Thanks @dawehner changes done as you suggested.

Shreya Shetty’s picture

Shreya Shetty’s picture

Status: Needs work » Needs review
mbovan’s picture

Issue tags: +Needs tests

I guess we should add tests here...

The last submitted patch, 6: 2596345-6.patch, failed testing.

dawehner’s picture

Yeah we need

Nitesh Pawar’s picture

Assigned: Unassigned » Nitesh Pawar
Nitesh Pawar’s picture

Assigned: Nitesh Pawar » Unassigned
Issue tags: -Needs tests
FileSize
2.38 KB
1.79 KB

Added test

mbovan’s picture

Hah, I was trying to upload the patch, but got the form notification that @Nitesh Pawar already uploaded different patch. :)

Anyway, I'm providing my (test) patch here. The interdiff is against #11.

Shreya Shetty’s picture

The last submitted patch, 19: deleting_a_view_should-2596345-18-TEST-ONLY.patch, failed testing.

Nitesh Pawar’s picture

dawehner’s picture

+++ b/core/modules/views_ui/src/Tests/DefaultViewsTest.php
@@ -142,6 +142,19 @@ function testDefaultViews() {
+
+    // 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('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');

Ideally we would add a drupalGet('/glossary') with assertResponse(200) to ensure that really this state changed.

Berdir’s picture

Status: Needs review » Needs work

Lets add that then, first check that /glossary is indeed a 200, then delete, then check 404.

mbovan’s picture

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Thank you for expanding the test coverage!

The last submitted patch, 25: deleting_a_view_should-2596345-25-TEST-ONLY.patch, failed testing.

The last submitted patch, 25: deleting_a_view_should-2596345-25-TEST-ONLY.patch, failed testing.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 25: deleting_a_view_should-2596345-25.patch, failed testing.

Nitesh Pawar’s picture

Status: Needs work » Reviewed & tested by the community

The last submitted patch, 25: deleting_a_view_should-2596345-25-TEST-ONLY.patch, failed testing.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

I discussed this with @dawehner and we concluded that views should implement the delete hook and do it there - because when hooks become events, or something else OO then we'll do the injection properly.

mbovan’s picture

mbovan’s picture

Status: Needs work » Needs review
dawehner’s picture

Status: Needs review » Needs work
+++ b/core/modules/views/views.module
@@ -804,3 +805,11 @@ function views_local_tasks_alter(&$local_tasks) {
+  // Rebuild routes after deleting a view.
+  \Drupal::service('router.builder')->setRebuildNeeded();

We could check whether the view has any routes and just in that particular case rebuild the router ...

The last submitted patch, 25: deleting_a_view_should-2596345-25-TEST-ONLY.patch, failed testing.

mbovan’s picture

Added the check if there is a routed display on a view before calling rebuild, as discussed with @dawehner here at Drupal Camp Vienna 2015.

The last submitted patch, 37: deleting_a_view_should-2596345-37-TEST-ONLY.patch, failed testing.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Awesome, thank you!

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed b6b7891 and pushed to 8.0.x and 8.1.x. Thanks!

  • alexpott committed b6b7891 on 8.1.x
    Issue #2596345 by mbovan, Nitesh Pawar, Shreya Shetty, dawehner:...

  • alexpott committed ea65def on
    Issue #2596345 by mbovan, Nitesh Pawar, Shreya Shetty, dawehner:...
edurenye’s picture

Status: Fixed » Needs work

Now we have to remove the rebuilds in PastDBTest::testViews and the @todo messages, not sure if here or in a followup.

edurenye’s picture

Status: Needs work » Fixed

Sorry for that, I thougt that it was in the module.

dawehner’s picture

Now we have to remove the rebuilds in PastDBTest::testViews and the @todo messages, not sure if here or in a followup.

If you find any in views, feel free to open a follow up!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.