\Drupal\views\Plugin\Menu\ViewsMenuLink::isDeletable returns TRUE even though it doesn't specify delete route

Created on 17 August 2023, 11 months ago
Updated 12 January 2024, 6 months ago

Problem/Motivation

I noticed that in Umami, on the main navigation edit page there are <a> elements without href in some of the menu link dropbutton trays:

It turns out that \Drupal\views\Plugin\Menu\ViewsMenuLink::isDeletable returns TRUE even though it doesn't specify a delete route 🤔

Proposed resolution

In core/lib/Drupal/Core/Menu/MenuLinkBase.php check if routes exist before adding links.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
Views 

Last updated 1 minute ago

Created by

🇫🇮Finland lauriii Finland

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @lauriii
  • Status changed to Needs review 11 months ago
  • last update 11 months ago
    30,040 pass, 2 fail
  • 🇫🇮Finland lauriii Finland

    Testing what test bot says.

  • Status changed to Needs work 11 months ago
  • 🇫🇮Finland lauriii Finland

    Looks like \Drupal\Core\Menu\MenuLinkManager::deleteInstance checks if the menu link is deletable and is triggered by \Drupal\views\Plugin\views\display\PathPluginBase::remove on view deletion.

    I can think of two potential approaches:

    1. Return link to the Views UI edit page from \Drupal\views\Plugin\Menu\ViewsMenuLink::getDeleteRoute. This might be confusing and I'm not sure what we should do when Views UI is not enabled.
    2. Return \Drupal\Core\Url object that the user never has access to, essentially preventing rendering the delete link in the operations. I couldn't find utilities for this so not sure if there's a clean way to do this without introducing this.
  • Status changed to Needs review 11 months ago
  • last update 11 months ago
    30,036 pass, 1 fail
  • 🇫🇮Finland lauriii Finland

    Here's a third option; check that a route is defined before creating the link in \Drupal\Core\Menu\MenuLinkBase::getOperations.

  • First commit to issue fork.
  • Merge request !5796Check for operation routes → (Open) created by Lendude
  • Status changed to Needs work 7 months ago
  • 🇳🇱Netherlands Lendude Amsterdam

    Option 3 sounds/looks good. Tried to reproduce the test fail locally, biut this test fails locally on HEAD too since it has a weird use of $base_path that doesn't work when running the test on '/'
    When for convience I remove the base_path usage, the test is green. So lets see what happens on Gitlab first

  • 🇳🇱Netherlands Lendude Amsterdam

    Hmm ok no idea why it failed on Drupal CI, but green now ¯\_(ツ)_/¯

    Just needs some test coverage than I guess.

  • Status changed to Needs review 7 months ago
  • 🇳🇱Netherlands Lendude Amsterdam

    Added a test, chose a Unit test in this case since we are messing with a base class. Setting this up for a functional test would maybe involve depending on Views since that is probably the only place this happens, which we don't want for a test for the menu system

  • Status changed to RTBC 7 months ago
  • 🇺🇸United States smustgrave

    Updated IS to include my best take at what the proposed solution is

    Ran the test-only feature

    There were 2 failures:
    1) Drupal\Tests\Core\Menu\MenuLinkBaseTest::testGetOperations with data set "is_resettable" (true)
    Failed asserting that an array does not have the key 'reset'.
    /builds/issue/drupal-3381770/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:121
    /builds/issue/drupal-3381770/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:55
    /builds/issue/drupal-3381770/core/tests/Drupal/Tests/Core/Menu/MenuLinkBaseTest.php:35
    /builds/issue/drupal-3381770/vendor/phpunit/phpunit/src/Framework/TestResult.php:728
    /builds/issue/drupal-3381770/vendor/phpunit/phpunit/src/Framework/TestSuite.php:684
    /builds/issue/drupal-3381770/vendor/phpunit/phpunit/src/Framework/TestSuite.php:684
    /builds/issue/drupal-3381770/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:651
    /builds/issue/drupal-3381770/vendor/phpunit/phpunit/src/TextUI/Command.php:144
    /builds/issue/drupal-3381770/vendor/phpunit/phpunit/src/TextUI/Command.php:97
    2) Drupal\Tests\Core\Menu\MenuLinkBaseTest::testGetOperations with data set "is_not_resettable" (false)
    Failed asserting that an array does not have the key 'delete'.
    /builds/issue/drupal-3381770/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:121
    /builds/issue/drupal-3381770/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:55
    /builds/issue/drupal-3381770/core/tests/Drupal/Tests/Core/Menu/MenuLinkBaseTest.php:34
    /builds/issue/drupal-3381770/vendor/phpunit/phpunit/src/Framework/TestResult.php:728
    /builds/issue/drupal-3381770/vendor/phpunit/phpunit/src/Framework/TestSuite.php:684
    /builds/issue/drupal-3381770/vendor/phpunit/phpunit/src/Framework/TestSuite.php:684
    /builds/issue/drupal-3381770/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:651
    /builds/issue/drupal-3381770/vendor/phpunit/phpunit/src/TextUI/Command.php:144
    /builds/issue/drupal-3381770/vendor/phpunit/phpunit/src/TextUI/Command.php:97
    FAILURES!
    Tests: 2, Assertions: 5, Failures: 2.
    

    Was able to also verify the screenshot on an umami install. Checking that the route exists before rendering the link seemed to work.

  • 🇳🇿New Zealand quietone New Zealand

    I'm triaging RTBC issues . I read the IS and the comments. I didn't find any unanswered questions or other work to do. And I see that there is agreement on the fix.

    I also tested this today and the change works as expected.

    Leaving at RTBC.

  • Status changed to Needs work 6 months ago
  • 🇬🇧United Kingdom longwave UK

    Unit tests now need strict_types enabled.

    FILE: ...e-commits/core/tests/Drupal/Tests/Core/Menu/MenuLinkBaseTest.php
    ----------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ----------------------------------------------------------------------
     1 | ERROR | [x] Missing declare(strict_types=1).
    ----------------------------------------------------------------------
    
    FILE: ...re/tests/Drupal/Tests/Core/Menu/MenuLinkNoOperationLinksMock.php
    ----------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ----------------------------------------------------------------------
     1 | ERROR | [x] Missing declare(strict_types=1).
    ----------------------------------------------------------------------
    
Production build 0.69.0 2024