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

CommentFileSizeAuthor
#8 3083757-8.patch6.86 KBmarthinal
#2 3083757-2.patch6.82 KBmarthinal
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:

Comments

pankajxenix created an issue. See original summary.

marthinal’s picture

StatusFileSize
new6.82 KB

I have the same error. It works with this patch

marthinal’s picture

Version: 8.x-1.5 » 8.x-1.9
Status: Active » Needs review
marthinal’s picture

Title: Mega menu showing error when same menu. » Mega menu showing error when saving menu
marthinal’s picture

I can reproduce it when I try to change the order of the menus.

jwilson3’s picture

Status: Needs review » Reviewed & tested by the community

Patch in #2 works. Thanks @Marthinal

jwilson3’s picture

Title: Mega menu showing error when saving menu » Mega menu fatal error when reordering Drupal menu items
marthinal’s picture

StatusFileSize
new6.86 KB

Rerolled

marthinal’s picture

Status: Reviewed & tested by the community » Needs review
jwilson3’s picture

Version: 8.x-1.9 » 8.x-1.11
jwilson3’s picture

Status: Needs review » Reviewed & tested by the community
roland.molnar’s picture

Status: Reviewed & tested by the community » Needs work

I applied the patch in #8, but now I get this error for some menu items:

Notice: Trying to get property '0' of non-object in Drupal\we_megamenu\WeMegaMenuBuilder::dragDropMenuItems() (line 599 of modules/contrib/we_megamenu/src/WeMegaMenuBuilder.php).
Drupal\we_megamenu\WeMegaMenuBuilder::dragDropMenuItems('main', 'MYTHEMENAME', Object, Array) (Line: 744)
we_megamenu_entity_presave(Object, 'menu')
call_user_func_array('we_megamenu_entity_presave', Array) (Line: 403)
Drupal\Core\Extension\ModuleHandler->invokeAll('entity_presave', Array) (Line: 349)
Drupal\Core\Config\Entity\ConfigEntityStorage->invokeHook('presave', Object) (Line: 500)
Drupal\Core\Entity\EntityStorageBase->doPreSave(Object) (Line: 454)
Drupal\Core\Entity\EntityStorageBase->save(Object) (Line: 263)
Drupal\Core\Config\Entity\ConfigEntityStorage->save(Object) (Line: 395)
Drupal\Core\Entity\EntityBase->save() (Line: 616)
Drupal\Core\Config\Entity\ConfigEntityBase->save() (Line: 100)
Drupal\system\Entity\Menu->save() (Line: 180)
Drupal\menu_ui\MenuForm->save(Array, Object)
call_user_func_array(Array, Array) (Line: 114)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 52)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 593)
Drupal\Core\Form\FormBuilder->processForm('menu_edit_form', Array, Object) (Line: 321)
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)

Notice: Trying to get property 'col_content' of non-object in Drupal\we_megamenu\WeMegaMenuBuilder::dragDropMenuItems() (line 599 of modules/contrib/we_megamenu/src/WeMegaMenuBuilder.php).
Drupal\we_megamenu\WeMegaMenuBuilder::dragDropMenuItems('main', 'MYTHEMENAME', Object, Array) (Line: 744)
we_megamenu_entity_presave(Object, 'menu')
call_user_func_array('we_megamenu_entity_presave', Array) (Line: 403)
Drupal\Core\Extension\ModuleHandler->invokeAll('entity_presave', Array) (Line: 349)
Drupal\Core\Config\Entity\ConfigEntityStorage->invokeHook('presave', Object) (Line: 500)
Drupal\Core\Entity\EntityStorageBase->doPreSave(Object) (Line: 454)
Drupal\Core\Entity\EntityStorageBase->save(Object) (Line: 263)
Drupal\Core\Config\Entity\ConfigEntityStorage->save(Object) (Line: 395)
Drupal\Core\Entity\EntityBase->save() (Line: 616)
Drupal\Core\Config\Entity\ConfigEntityBase->save() (Line: 100)
Drupal\system\Entity\Menu->save() (Line: 180)
Drupal\menu_ui\MenuForm->save(Array, Object)
call_user_func_array(Array, Array) (Line: 114)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 52)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 593)
Drupal\Core\Form\FormBuilder->processForm('menu_edit_form', Array, Object) (Line: 321)
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)
Warning: Attempt to modify property '0' of non-object in Drupal\we_megamenu\WeMegaMenuBuilder::dragDropMenuItems() (line 604 of modules/contrib/we_megamenu/src/WeMegaMenuBuilder.php).
Drupal\we_megamenu\WeMegaMenuBuilder::dragDropMenuItems('main', 'MYTHEMENAME', Object, Array) (Line: 744)
we_megamenu_entity_presave(Object, 'menu')
call_user_func_array('we_megamenu_entity_presave', Array) (Line: 403)
Drupal\Core\Extension\ModuleHandler->invokeAll('entity_presave', Array) (Line: 349)
Drupal\Core\Config\Entity\ConfigEntityStorage->invokeHook('presave', Object) (Line: 500)
Drupal\Core\Entity\EntityStorageBase->doPreSave(Object) (Line: 454)
Drupal\Core\Entity\EntityStorageBase->save(Object) (Line: 263)
Drupal\Core\Config\Entity\ConfigEntityStorage->save(Object) (Line: 395)
Drupal\Core\Entity\EntityBase->save() (Line: 616)
Drupal\Core\Config\Entity\ConfigEntityBase->save() (Line: 100)
Drupal\system\Entity\Menu->save() (Line: 180)
Drupal\menu_ui\MenuForm->save(Array, Object)
call_user_func_array(Array, Array) (Line: 114)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 52)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 593)
Drupal\Core\Form\FormBuilder->processForm('menu_edit_form', Array, Object) (Line: 321)
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)

roland.molnar’s picture

I'm debugging the code and it looks like

$menu_config->menu_config->{$key_menu}->rows_content[$row_count]

is sometimes an Array, sometimes a Class.
As I'm not familiar whith what this code does, I'm not sure if the solution is simply wrap the code segment in another if

if (is_object($menu_config->menu_config->{$key_menu}->rows_content[$row_count]))

else skip these

or do something like

if (is_object($menu_config->menu_config->{$key_menu}->rows_content[$row_count])) {
 $tmp = $menu_config->menu_config->{$key_menu}->rows_content[$row_count]->{$col_count}->col_content;
} else {
 $tmp = $menu_config->menu_config->{$key_menu}->rows_content[$row_count][$col_count]->col_content; 
}

xaviemirmon made their first commit to this issue’s fork.

xaviemirmon’s picture

Version: 8.x-1.11 » 8.x-1.x-dev
Status: Needs work » Needs review

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.

  • rjjakes committed 4b86d200 on 8.x-1.x authored by xaviemirmon
    Issue #3083757 by marthinal, xaviemirmon, jwilson3, pankajlogical,...
rjjakes’s picture

Status: Needs review » Fixed

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

Status: Fixed » Closed (fixed)

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