Problem/Motivation

The redirection is not correctly handled when the top parent item is deleted. It means that the URL has always set the menu_link parameter in the query (even after all items are removed) and when tries to load it the response is an error.

The website encountered an unexpected error. Please try again later.

Drupal\Component\Plugin\Exception\PluginNotFoundException: Plugin ID 'menu_link_content:3224b8dd-c7c5-4805-a4c6-ab16c43cbc52' was not found. in Drupal\Core\Menu\MenuLinkManager->getDefinition() (line 206 of core/lib/Drupal/Core/Menu/MenuLinkManager.php).
Drupal\Core\Plugin\Factory\ContainerFactory->createInstance('menu_link_content:3224b8dd-c7c5-4805-a4c6-ab16c43cbc52', Array) (Line: 233)
Drupal\Core\Menu\MenuLinkManager->createInstance('menu_link_content:3224b8dd-c7c5-4805-a4c6-ab16c43cbc52') (Line: 91)
Drupal\bigmenu\BigMenuForm->buildOverviewFormWithDepth(Array, Object, 1, 'menu_link_content:3224b8dd-c7c5-4805-a4c6-ab16c43cbc52') (Line: 59)
Drupal\bigmenu\BigMenuForm->buildOverviewForm(Array, Object) (Line: 150)
Drupal\menu_ui\MenuForm->form(Array, Object) (Line: 149)
Drupal\Core\Entity\EntityForm->buildForm(Array, Object)
call_user_func_array(Array, Array) (Line: 532)
Drupal\Core\Form\FormBuilder->retrieveForm('menu_edit_form', Object) (Line: 278)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 91)
Drupal\Core\Controller\FormController->getContentResult(Object, Object) (Line: 39)
Drupal\layout_builder\Controller\LayoutBuilderHtmlEntityFormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 573)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 151)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 708)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Steps to reproduce

  1. Go to create a new menu "Test"
  2. Edit the test navigation here: /admin/structure/menu/manage/test
  3. Click “Add link” to add a menu item with the Test navigation at the parent
  4. Add another menu item, making the parent the item you just added
  5. Click on “Edit child items” on the menu item you added to the Test menu
  6. Delete the child item using the drop-down in the “Operations” column
  7. Notice that the "menu_link" parameter is always in the URL
  8. Once back on the page where you deleted the child item, delete the remaining parent item using the drop-down in the “Operations” column
  9. Here is when it throws an error because the menu_item doesn't exist anymore but in code tries to load it.

Proposed resolution

This issue can be fixed by checking if the "menu_item" exists, in the case that it doesn't then do a redirect to the current page without the query parameter. This can be done in bigmenu/src/BigMenuForm.php line 56. I created a patch that fixes it and could be considered for a review.

if ($menu_link && !$this->menuLinkManager->hasDefinition($menu_link)) {
  $response = new RedirectResponse(\Drupal::service('path.current')->getPath(), 302);
  $response->send();
}

Remaining tasks

Needs to be tested and verified by other developers.

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Issue fork bigmenu-3206459

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

alexito created an issue. See original summary.

KapilV’s picture

Status: Active » Needs review
FileSize
765 bytes

afsch’s picture

The patch in #2 is missing a dependency, here is an update:

afsch’s picture

Issue tags: +bigmenu
acbramley’s picture

Status: Needs review » Needs work
Issue tags: -menu, -bigmenu

Thank for for the bug report and detailed steps to reproduce. I think the easiest approach here is adding the hasDefinition check to the if statement around the code that attempts to call createInstance. We'll also need some tests here.

diff --git a/src/BigMenuForm.php b/src/BigMenuForm.php
index d428bc7..fbf95fd 100755
--- a/src/BigMenuForm.php
+++ b/src/BigMenuForm.php
@@ -84,7 +84,7 @@ class BigMenuForm extends MenuForm {
     $form['#attached']['library'][] = 'menu_ui/drupal.menu_ui.adminforms';

     // Add a link to go back to the full menu.
-    if ($menu_link) {
+    if ($menu_link && $this->menuLinkManager->hasDefinition($menu_link)) {
       /** @var \Drupal\Core\Menu\MenuLinkInterface $parent */
       $breadcrumbs = [];
       $parent = $this->menuLinkManager->createInstance($menu_link);
acbramley’s picture

Version: 2.0.0-rc1 » 2.x-dev
Status: Needs work » Needs review
FileSize
4.75 KB

Here's the fix + tests

  • acbramley committed 2a0e60b on 2.x
    Issue #3206459 by alexis_saransig, acbramley, kapilkumar0324: Redirect...
acbramley’s picture

Status: Needs review » Fixed

Committed and pushed, I'll roll a new stable release for this. Cheers!

Status: Fixed » Closed (fixed)

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