Problem/Motivation
When you try to save view modes settings for menu an error is occurred.
Steps to reproduce:
- Enable menu_item_extras module to provide view mode settings
- Add link to any menu
- Go to manage display of that menu and click on View Modes Settigs
- Save the view mode
- Get the following error message:
The website encountered an unexpected error. Please try again later.
Drupal\Core\Entity\Exception\UndefinedLinkTemplateException: No link template 'canonical' found for the 'menu' entity type in Drupal\Core\Entity\Entity->toUrl() (line 215 of core/lib/Drupal/Core/Entity/Entity.php).
Drupal\Core\Config\Entity\ConfigEntityBase->toUrl('canonical') (Line: 270)
Drupal\Core\Entity\Entity->toLink(Object) (Line: 126)
Drupal\menu_item_extras\MenuItemExtrasViewModesSettingsForm->save(Array, Object)
call_user_func_array(Array, Array) (Line: 111)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 51)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 585)
Drupal\Core\Form\FormBuilder->processForm('menu_view_modes_settings_form', Array, Object) (Line: 314)
Drupal\Core\Form\FormBuilder->buildForm('menu_view_modes_settings_form', Object) (Line: 74)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 576)
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}()
call_user_func_array(Object, Array) (Line: 153)
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: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 657)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
Proposed resolution
To add additional check in ConfigEntityBase->toUrl method to check if $rel value is 'canonical' and replace it with 'edit-form'.