Getting Undefined index: menu_name randomly when clearing cache. Complete error message returned to: /admin/config/development/performance - Notice: Undefined index: menu_name in menu_block_theme_suggestions_menu() (line 52 of sites/mountwashington.org/modules/menu_block/menu_block.module). menu_block_theme_suggestions_menu(Array)

Running a second "Clear all caches" immediately afterwards doesn't return the Notice.

I'm thinking this will probably need a fix similar to 2759019.

I'm on Drupal 8.1.6 with a clean install of menu block

I'm on

CommentFileSizeAuthor
#2 2765411.patch547 bytesshishirsuvarna
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

MtWashington created an issue. See original summary.

shishirsuvarna’s picture

FileSize
547 bytes

Hi,

Try this patch this might resolve the issue.

shishirsuvarna’s picture

Status: Active » Needs review
rrrob’s picture

JohnAlbin’s picture

Status: Needs review » Closed (duplicate)
JohnAlbin’s picture

Status: Closed (duplicate) » Postponed (maintainer needs more info)

Actually, this isn't a dupe.

However, I have no idea how this warning message would occur. The "menu" theme hook is defined to a have "menu_name" variable in drupal_common_theme(). So, theoretically, the menu_name variable will always be defined. no clue how it would become undefined in your setup. :\ Any thoughts?

In any event, the patch needs work; you can't create variables from within hook_theme_suggestions_HOOK().

monkeyhouse’s picture

I get the error as well, but only if I have caching disabled for development purposes. In my case, it appears to have something to do with the admin toolbar.

Drupal - 8.1.8
Menu Block - 8.x-1.2

menu_block_theme_suggestions_menu(Array)
call_user_func_array('menu_block_theme_suggestions_menu', Array) (Line: 402)
Drupal\Core\Extension\ModuleHandler->invokeAll('theme_suggestions_menu', Array) (Line: 230)
Drupal\Core\Theme\ThemeManager->render('menu__toolbar__admin', Array) (Line: 435)
Drupal\Core\Render\Renderer->doRender(Array, 1) (Line: 195)
Drupal\Core\Render\Renderer->render(Array, 1) (Line: 151)
Drupal\Core\Render\Renderer->Drupal\Core\Render\{closure}() (Line: 574)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 152)
Drupal\Core\Render\Renderer->renderPlain(Array) (Line: 327)
_toolbar_do_get_rendered_subtrees(Array)
call_user_func('_toolbar_do_get_rendered_subtrees', Array) (Line: 381)
Drupal\Core\Render\Renderer->doRender(Array, 1) (Line: 195)
Drupal\Core\Render\Renderer->render(Array, 1) (Line: 151)
Drupal\Core\Render\Renderer->Drupal\Core\Render\{closure}() (Line: 574)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 152)
Drupal\Core\Render\Renderer->renderPlain(Array) (Line: 297)
toolbar_get_rendered_subtrees() (Line: 355)
_toolbar_get_subtrees_hash() (Line: 167)
toolbar_toolbar()
call_user_func_array('toolbar_toolbar', Array) (Line: 402)
Drupal\Core\Extension\ModuleHandler->invokeAll('toolbar') (Line: 81)
Drupal\toolbar\Element\Toolbar::preRenderToolbar(Array)
call_user_func(Array, Array) (Line: 381)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 448)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 195)
Drupal\Core\Render\Renderer->render(Array) (Line: 468)
Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) (Line: 86)
__TwigTemplate_b0c6de61e5b8a39f737b732df00cc62af5fb88c3ae6ea91045e0f26871b1a76a->doDisplay(Array, Array) (Line: 387)
Twig_Template->displayWithErrorHandling(Array, Array) (Line: 355)
Twig_Template->display(Array) (Line: 366)
Twig_Template->render(Array) (Line: 64)
twig_render_template('themes/contrib/bootstrap/templates/system/html.html.twig', Array) (Line: 384)
Drupal\Core\Theme\ThemeManager->render('html', Array) (Line: 435)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 195)
Drupal\Core\Render\Renderer->render(Array) (Line: 147)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 574)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 148)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.view', Object) (Line: 149)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 64)
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: 98)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 77)
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: 628)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
criscom’s picture

I am also getting this error on a multilingual D8 site. It's is currently hard to say when it started to occur nor why. It could be related to https://www.drupal.org/node/2769705 and https://www.drupal.org/node/2780423 (all token module issues). Hope this helps to track the problem down.

thmohd’s picture

#2 Solved it for me. Thanks

ChandeepKhosa’s picture

I ran into the error mentioned https://www.drupal.org/node/2759019, installed the patch in #11 and that error disappeared.
Afterwards I noticed the error on this page occurred on a page where I have inserted a view block via display suite into a content type. I'm not sure if this was happening as a result of the first patch appalied.
The patch above in #2 fixed this for me too

JohnAlbin’s picture

As I said in #6 above, the patch in #2 is not acceptable, please stop saying "works for me".

@monkeyhouse and @criscom: Thank you for the hints! I'll keep trying to reproduce.

duntuk’s picture

#2 fixed the issue for me. Even applied it manually to 8.x-1.x-dev-2016-Sep-02 version (which had the same error).

 function menu_block_theme_suggestions_menu(array $variables) {
   $suggestions = array();
+  $variables['menu_name'] = isset($variables['menu_name']) ? $variables['menu_name'] : "";
   $menu_name = strtr($variables['menu_name'], '-', '_');
   $suggestion_prefix = 'menu__menu_block_' . $menu_name . '_region_';
 
JohnAlbin’s picture

Seriously?

JohnAlbin’s picture

Assigned: Unassigned » JohnAlbin
Status: Postponed (maintainer needs more info) » Active

I figured it out. When the requested menu tree contains no links, then $this->menuTree->build($tree) returns a collapsed render array that only contains a #cache entry. Menu block was overriding the default #theme entry to add a theme hook suggestion, but it was incorrectly doing that even when the render array didn't have a #theme entry. That meant the menu theme hook was being fired without the proper variables, like menu_name.

  • JohnAlbin committed 5f09f6c on 8.x-1.x
    Issue #2765411 by shishirsuvarna, JohnAlbin, MtWashington, monkeyhouse,...
JohnAlbin’s picture

Title: Undefined index: menu_name » PHP notice "Undefined index: menu_name" when menu tree is empty
Assigned: JohnAlbin » Unassigned
Status: Active » Fixed

Status: Fixed » Closed (fixed)

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

StryKaizer’s picture

Status: Closed (fixed) » Needs work

It looks like this code is gone in 8.x-1.x HEAD.

Prolly related to the fact I'm experiencing this issue with latest head, or was this fixed using different code?

EDIT:
tried 5f09f6c too, which did not solve the issue in my case

JohnAlbin’s picture

Status: Needs work » Postponed (maintainer needs more info)

I just double checked and its definitely in 8.x-1.x. And in 8.x-1.4.

I had to alter these lines of code in #2795095: PHP Notice: Undefined index: #id when used with Context module, so maybe that's why it's confusing?

Please try 8.x-1.4 and verify if you are still having the problem.

joelpittet’s picture

Version: 8.x-1.1 » 8.x-1.x-dev
Status: Postponed (maintainer needs more info) » Fixed

Assuming fixed since no reply.

Status: Fixed » Closed (fixed)

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

douggreen’s picture