When changing the order of menu items (in /admin/structure/menu/manage/main), I get "The website encountered an unexpected error. Please try again later."

In the logs I have:

Error: Call to undefined method Drupal\Core\Entity\Sql\SqlContentEntityStorage::loadParents() in _content_sync_db_to_entity() (line 654 of /usr/share/drupal/docroot/modules/contrib/content_sync/content_sync.batch.inc) #0 /usr/share/drupal/docroot/modules/contrib/content_sync/content_sync.module(215): _content_sync_db_to_entity('menu_link_conte...', 'menu_link_conte...', '2') #1 [internal function]: content_sync_entity_update(Object(Drupal\menu_link_content\Entity\MenuLinkContent)) #2 /usr/share/drupal/docroot/core/lib/Drupal/Core/Extension/ModuleHandler.php(402): call_user_func_array('content_sync_en...', Array) #3 /usr/share/drupal/docroot/core/lib/Drupal/Core/Entity/EntityStorageBase.php(169): Drupal\Core\Extension\ModuleHandler->invokeAll('entity_update', Array) #4 /usr/share/drupal/docroot/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php(441): Drupal\Core\Entity\EntityStorageBase->invokeHook('update', Object(Drupal\menu_link_content\Entity\MenuLinkContent)) #5 /usr/share/drupal/docroot/core/lib/Drupal/Core/Entity/EntityStorageBase.php(470): Drupal\Core\Entity\ContentEntityStorageBase->invokeHook('update', Object(Drupal\menu_link_content\Entity\MenuLinkContent)) #6 /usr/share/drupal/docroot/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php(326): Drupal\Core\Entity\EntityStorageBase->doPostSave(Object(Drupal\menu_link_content\Entity\MenuLinkContent), true) #7 /usr/share/drupal/docroot/core/lib/Drupal/Core/Entity/EntityStorageBase.php(395): Drupal\Core\Entity\ContentEntityStorageBase->doPostSave(Object(Drupal\menu_link_content\Entity\MenuLinkContent), true) #8 /usr/share/drupal/docroot/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php(768): Drupal\Core\Entity\EntityStorageBase->save(Object(Drupal\menu_link_content\Entity\MenuLinkContent)) #9 /usr/share/drupal/docroot/core/modules/menu_link_content/src/Plugin/Menu/MenuLinkContent.php(217): Drupal\Core\Entity\Sql\SqlContentEntityStorage->save(Object(Drupal\menu_link_content\Entity\MenuLinkContent)) #10 /usr/share/drupal/docroot/core/lib/Drupal/Core/Menu/MenuLinkManager.php(369): Drupal\menu_link_content\Plugin\Menu\MenuLinkContent->updateLink(Array, true) #11 /usr/share/drupal/docroot/core/modules/menu_ui/src/MenuForm.php(471): Drupal\Core\Menu\MenuLinkManager->updateDefinition('menu_link_conte...', Array) #12 /usr/share/drupal/docroot/core/modules/menu_ui/src/MenuForm.php(185): Drupal\menu_ui\MenuForm->submitOverviewForm(Array, Object(Drupal\Core\Form\FormState)) #13 [internal function]: Drupal\menu_ui\MenuForm->submitForm(Array, Object(Drupal\Core\Form\FormState)) #14 /usr/share/drupal/docroot/core/lib/Drupal/Core/Form/FormSubmitter.php(111): call_user_func_array(Array, Array) #15 /usr/share/drupal/docroot/core/lib/Drupal/Core/Form/FormSubmitter.php(51): Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object(Drupal\Core\Form\FormState)) #16 /usr/share/drupal/docroot/core/lib/Drupal/Core/Form/FormBuilder.php(585): Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object(Drupal\Core\Form\FormState)) #17 /usr/share/drupal/docroot/core/lib/Drupal/Core/Form/FormBuilder.php(314): Drupal\Core\Form\FormBuilder->processForm('menu_edit_form', Array, Object(Drupal\Core\Form\FormState)) #18 /usr/share/drupal/docroot/core/lib/Drupal/Core/Controller/FormController.php(74): Drupal\Core\Form\FormBuilder->buildForm('menu_edit_form', Object(Drupal\Core\Form\FormState)) #19 [internal function]: Drupal\Core\Controller\FormController->getContentResult(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\RouteMatch)) #20 /usr/share/drupal/docroot/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array) #21 /usr/share/drupal/docroot/core/lib/Drupal/Core/Render/Renderer.php(574): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() #22 /usr/share/drupal/docroot/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure)) #23 /usr/share/drupal/docroot/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) #24 [internal function]: Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() #25 /usr/share/drupal/vendor/symfony/http-kernel/HttpKernel.php(144): call_user_func_array(Object(Closure), Array) #26 /usr/share/drupal/vendor/symfony/http-kernel/HttpKernel.php(64): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1) #27 /usr/share/drupal/docroot/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #28 /usr/share/drupal/docroot/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #29 /usr/share/drupal/docroot/core/modules/page_cache/src/StackMiddleware/PageCache.php(99): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #30 /usr/share/drupal/docroot/core/modules/page_cache/src/StackMiddleware/PageCache.php(78): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true) #31 /usr/share/drupal/docroot/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #32 /usr/share/drupal/docroot/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(50): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #33 /usr/share/drupal/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #34 /usr/share/drupal/docroot/core/lib/Drupal/Core/DrupalKernel.php(656): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #35 /usr/share/drupal/docroot/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request)) #36 {main}.

In the config of the module, there's an error stating the sync directory is not found.

Uninstalling the module solves the error.

Comments

clauded created an issue. See original summary.

blanca.esqueda’s picture

Hi Clauded,

We try to replicate the error moving the menu options.
About the sync directory not found, did you added the folder and declared in settings.php?

yogeshchaugule8’s picture

Even I'm facing same issue while re-arranging the menu items on Menu page or during create/edit of menu items using UI, only for menu items created using UI.

I do've the $content_directories variable set in settings.php file.

yogeshchaugule8’s picture

After some debugging, I found that the MenuLinkContent Entity handle the parent differently and also doesn't define its own storage handler like Taxonomy Module does, instead uses the one defined in core i.e. Drupal\Core\Entity\Sql\SqlContentEntityStorage. The SqlContentEntityStorage doesn't has any method called loadParents().

Here is a workaround patch which alternatively get the Parent uuid based on Entity. The patch also include changes for importing.

steveoriol’s picture

The patch #4 works for me, thanks you.

blanca.esqueda’s picture

Thank you @yogeshchaugule8,

The error reported doesn't happen on the new version 8.x-2.x, but your patch helped me to complete parents dependencies for menu links.

Added a piece of code to the new version 8.x-2.x based on your patch and credited you:
https://www.drupal.org/node/2865869/committers

Please feel free to pull version 8.x-2.x and do some testing, but be aware that the yaml files are different from one version to the other as some changes were needed to implement new functionality. (that means the same version has to run on the source and target sites).

blanca.esqueda’s picture

Version: 8.x-1.2 » 8.x-2.0
Status: Active » Fixed

Menu parent fix has been included to release 8.x-2.0

blanca.esqueda’s picture

Status: Fixed » Closed (fixed)