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
- Go to create a new menu "Test"
- Edit the test navigation here: /admin/structure/menu/manage/test
- Click “Add link” to add a menu item with the Test navigation at the parent
- Add another menu item, making the parent the item you just added
- Click on “Edit child items” on the menu item you added to the Test menu
- Delete the child item using the drop-down in the “Operations” column
- Notice that the "menu_link" parameter is always in the URL
- Once back on the page where you deleted the child item, delete the remaining parent item using the drop-down in the “Operations” column
- 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
Comment | File | Size | Author |
---|---|---|---|
#7 | 3206459-7.patch | 4.75 KB | acbramley |
Issue fork bigmenu-3206459
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:
Comments
Comment #2
KapilV CreditAttribution: KapilV as a volunteer and at Innoraft for Drupal Association commentedComment #4
afschThe patch in #2 is missing a dependency, here is an update:
Comment #5
afschComment #6
acbramley CreditAttribution: acbramley at PreviousNext commentedThank 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 callcreateInstance
. We'll also need some tests here.Comment #7
acbramley CreditAttribution: acbramley at PreviousNext commentedHere's the fix + tests
Comment #9
acbramley CreditAttribution: acbramley at PreviousNext commentedCommitted and pushed, I'll roll a new stable release for this. Cheers!