Mega menu fatal error when reordering Drupal menu items

Created on 26 September 2019, about 5 years ago
Updated 27 March 2023, over 1 year ago

Hey,

When I try to save my menu it's showing me Error. Error: Cannot use object of type stdClass as array in Drupal\we_megamenu\WeMegaMenuBuilder::dragDropMenuItems() (line 584 of /var/www/elementis/docroot/modules/contrib/we_megamenu/src/WeMegaMenuBuilder.php) #0 /var/www/elementis/docroot/modules/contrib/we_megamenu/we_megamenu.module(743): Drupal\we_megamenu\WeMegaMenuBuilder::dragDropMenuItems('main', 'elementis', Object(stdClass), Array) #1 [internal function]: we_megamenu_entity_presave(Object(Drupal\system\Entity\Menu), 'menu') #2 /var/www/elementis/docroot/core/lib/Drupal/Core/Extension/ModuleHandler.php(403): call_user_func_array('we_megamenu_ent...', Array) #3 /var/www/elementis/docroot/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php(349): Drupal\Core\Extension\ModuleHandler->invokeAll('entity_presave', Array) #4 /var/www/elementis/docroot/core/lib/Drupal/Core/Entity/EntityStorageBase.php(491): Drupal\Core\Config\Entity\ConfigEntityStorage->invokeHook('presave', Object(Drupal\system\Entity\Menu)) #5 /var/www/elementis/docroot/core/lib/Drupal/Core/Entity/EntityStorageBase.php(445): Drupal\Core\Entity\EntityStorageBase->doPreSave(Object(Drupal\system\Entity\Menu)) #6 /var/www/elementis/docroot/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php(263): Drupal\Core\Entity\EntityStorageBase->save(Object(Drupal\system\Entity\Menu)) #7 /var/www/elementis/docroot/core/lib/Drupal/Core/Entity/EntityBase.php(394): Drupal\Core\Config\Entity\ConfigEntityStorage->save(Object(Drupal\system\Entity\Menu)) #8 /var/www/elementis/docroot/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php(613): Drupal\Core\Entity\EntityBase->save() #9 /var/www/elementis/docroot/core/modules/system/src/Entity/Menu.php(99): Drupal\Core\Config\Entity\ConfigEntityBase->save() #10 /var/www/elementis/docroot/core/modules/menu_ui/src/MenuForm.php(179): Drupal\system\Entity\Menu->save() #11 [internal function]: Drupal\menu_ui\MenuForm->save(Array, Object(Drupal\Core\Form\FormState)) #12 /var/www/elementis/docroot/core/lib/Drupal/Core/Form/FormSubmitter.php(111): call_user_func_array(Array, Array) #13 /var/www/elementis/docroot/core/lib/Drupal/Core/Form/FormSubmitter.php(51): Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object(Drupal\Core\Form\FormState)) #14 /var/www/elementis/docroot/core/lib/Drupal/Core/Form/FormBuilder.php(590): Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object(Drupal\Core\Form\FormState)) #15 /var/www/elementis/docroot/core/lib/Drupal/Core/Form/FormBuilder.php(319): Drupal\Core\Form\FormBuilder->processForm('menu_edit_form', Array, Object(Drupal\Core\Form\FormState)) #16 /var/www/elementis/docroot/core/lib/Drupal/Core/Controller/FormController.php(93): Drupal\Core\Form\FormBuilder->buildForm('menu_edit_form', Object(Drupal\Core\Form\FormState)) #17 [internal function]: Drupal\Core\Controller\FormController->getContentResult(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\RouteMatch)) #18 /var/www/elementis/docroot/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array) #19 /var/www/elementis/docroot/core/lib/Drupal/Core/Render/Renderer.php(582): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() #20 /var/www/elementis/docroot/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure)) #21 /var/www/elementis/docroot/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) #22 /var/www/elementis/vendor/symfony/http-kernel/HttpKernel.php(151): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() #23 /var/www/elementis/vendor/symfony/http-kernel/HttpKernel.php(68): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1) #24 /var/www/elementis/docroot/modules/contrib/simple_oauth/src/HttpMiddleware/BasicAuthSwap.php(67): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #25 /var/www/elementis/docroot/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Drupal\simple_oauth\HttpMiddleware\BasicAuthSwap->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #26 /var/www/elementis/docroot/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #27 /var/www/elementis/docroot/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #28 /var/www/elementis/docroot/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true) #29 /var/www/elementis/docroot/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #30 /var/www/elementis/docroot/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #31 /var/www/elementis/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #32 /var/www/elementis/docroot/core/lib/Drupal/Core/DrupalKernel.php(693): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #33 /var/www/elementis/docroot/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request)) #34 {main}.

Anyone help me to solve this issue.
Thank you

🐛 Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

🇮🇳India pankajlogical Jaipur

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • First commit to issue fork.
  • Status changed to Needs review over 1 year ago
  • 🇬🇧United Kingdom xaviemirmon Brighton

    Hi @roland.molnar

    I've debugged this issue to see why some instances of rows_content were stored as objects versus an array as intended. This is caused by various unsets removing items in arrays and not resetting the index. When the menu_config data is then passed through the json_encode() function, it's perceiving that attribute as an object.

    [rows_content] => Array
                            (
                                [1] => Array
                                    (
                                        [0] => stdClass Object
                                            (
                                                [col_config] => stdClass Object
                                                    (
                                                        [hidewhencollapse] => 
                                                        [type] => we-mega-menu-col
                                                        [width] => 12
                                                        [block] => 
                                                        [class] => 
                                                        [block_title] => 1
                                                    )
    
                                                [col_content] => Array
                                                    (
                                                    )
    
                                            )
    
                                    )
    
                            )

    is being encoded as

    "rows_content": {
            "1": [
              {
                "col_config": {
                  "hidewhencollapse": "",
                  "type": "we-mega-menu-col",
                  "width": "12",
                  "block": "",
                  "class": "",
                  "block_title": "1"
                },
                "col_content": []
              }
            ]
          },

    I've created an issue fork which fixing the problem by correctly re-indexing the array if items are removed to that the first index is 0.

  • @xaviemirmon opened merge request.
  • Status changed to Fixed over 1 year ago
  • 🇬🇧United Kingdom rjjakes

    I merged the fix by xaviemirmon to 8-x.1-x as this fixed the underlying issue instead of working around it.

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

Production build 0.71.5 2024