After upgrading to version 4.4.0 I am getting the following php error if I try to use the login page:

/user/login

Warning: Invalid argument supplied for foreach() in responsive_menu_responsive_menu_off_canvas_tree_alter() (line 237 of /var/www/html/swportl/web/modules/contrib/responsive_menu/responsive_menu.module)
#0 /var/www/html/swportl/web/core/includes/bootstrap.inc(600): _drupal_error_handler_real()
#1 /var/www/html/swportl/web/modules/contrib/responsive_menu/responsive_menu.module(237): _drupal_error_handler()
#2 /var/www/html/swportl/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(539): responsive_menu_responsive_menu_off_canvas_tree_alter()
#3 /var/www/html/swportl/web/modules/contrib/responsive_menu/src/OffCanvas.php(81): Drupal\Core\Extension\ModuleHandler->alter()
#4 [internal function]: Drupal\responsive_menu\OffCanvas::preRender()
#5 /var/www/html/swportl/web/core/lib/Drupal/Core/Security/DoTrustedCallbackTrait.php(100): call_user_func_array()
#6 /var/www/html/swportl/web/core/lib/Drupal/Core/Render/Renderer.php(781): Drupal\Core\Render\Renderer->doTrustedCallback()
#7 /var/www/html/swportl/web/core/lib/Drupal/Core/Render/Renderer.php(372): Drupal\Core\Render\Renderer->doCallback()
#8 /var/www/html/swportl/web/core/lib/Drupal/Core/Render/Renderer.php(444): Drupal\Core\Render\Renderer->doRender()
#9 /var/www/html/swportl/web/core/lib/Drupal/Core/Render/Renderer.php(444): Drupal\Core\Render\Renderer->doRender()
#10 /var/www/html/swportl/web/core/lib/Drupal/Core/Render/Renderer.php(200): Drupal\Core\Render\Renderer->doRender()
#11 /var/www/html/swportl/web/core/lib/Drupal/Core/Template/TwigExtension.php(501): Drupal\Core\Render\Renderer->render()
#12 /var/www/html/swportl/web/sites/default/files/php/twig/5f4e58d3c9b4f_html.html.twig_eon3EIGzuzH7mUC56rOIrzEDe/QFB8njPsJbri_hnzLG8sOw2oDeGPPtrfa6JOFrQQxq8.php(106): Drupal\Core\Template\TwigExtension->escapeFilter()
#13 /var/www/html/swportl/vendor/twig/twig/src/Template.php(455): __TwigTemplate_70b01aa08284323232cf623e10f0fa6d7d8f419f55cf2d9c5e434e03ccf5d388->doDisplay()
#14 /var/www/html/swportl/vendor/twig/twig/src/Template.php(422): Twig\Template->displayWithErrorHandling()
#15 /var/www/html/swportl/vendor/twig/twig/src/Template.php(434): Twig\Template->display()
#16 /var/www/html/swportl/web/core/themes/engines/twig/twig.engine(64): Twig\Template->render()
#17 /var/www/html/swportl/web/core/lib/Drupal/Core/Theme/ThemeManager.php(384): twig_render_template()
#18 /var/www/html/swportl/web/core/lib/Drupal/Core/Render/Renderer.php(431): Drupal\Core\Theme\ThemeManager->render()
#19 /var/www/html/swportl/web/core/lib/Drupal/Core/Render/Renderer.php(200): Drupal\Core\Render\Renderer->doRender()
#20 /var/www/html/swportl/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(147): Drupal\Core\Render\Renderer->render()
#21 /var/www/html/swportl/web/core/lib/Drupal/Core/Render/Renderer.php(573): Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}()
#22 /var/www/html/swportl/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(148): Drupal\Core\Render\Renderer->executeInRenderContext()
#23 /var/www/html/swportl/web/core/lib/Drupal/Core/EventSubscriber/MainContentViewSubscriber.php(90): Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse()
#24 [internal function]: Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray()
#25 /var/www/html/swportl/web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(111): call_user_func()
#26 /var/www/html/swportl/vendor/symfony/http-kernel/HttpKernel.php(156): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch()
#27 /var/www/html/swportl/vendor/symfony/http-kernel/HttpKernel.php(68): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
#28 /var/www/html/swportl/web/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle()
#29 /var/www/html/swportl/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle()
#30 /var/www/html/swportl/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(191): Drupal\Core\StackMiddleware\KernelPreHandle->handle()
#31 /var/www/html/swportl/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(128): Drupal\page_cache\StackMiddleware\PageCache->fetch()
#32 /var/www/html/swportl/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(82): Drupal\page_cache\StackMiddleware\PageCache->lookup()
#33 /var/www/html/swportl/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\page_cache\StackMiddleware\PageCache->handle()
#34 /var/www/html/swportl/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
#35 /var/www/html/swportl/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
#36 /var/www/html/swportl/web/core/lib/Drupal/Core/DrupalKernel.php(708): Stack\StackedHttpKernel->handle()
#37 /var/www/html/swportl/web/index.php(19): Drupal\Core\DrupalKernel->handle()
#38 {main}

Comments

JD_1 created an issue. See original summary.

wgsimon’s picture

I have the same issue. After clearing the cache, this happens once and then goes away. It's triggered by a non-logged-in user on any page, as far as I can tell.

dbielke1986’s picture

After clearing the cache, this happens once and then goes away. It's triggered by a non-logged-in user on any page, as far as I can tell.

I can confirm this.

tanc’s picture

Thanks for the big report! A quick glance looks like the foreach should be wrapped in a condition to check if the array contains the #items property

https://git.drupalcode.org/project/responsive_menu/-/blob/4.3.x/responsi...

It would be good to know whether that older patch that was committed recently still works as intended: #2826484: Add a unique class to off-canvas menu items

dbielke1986’s picture

Thanks Tanc for the Feedback. I will have a look on this tomorrow:

It would be good to know whether that older patch that was committed recently still works as intended: #2826484: Add a unique class to off-canvas menu items

dbielke1986’s picture

StatusFileSize
new2.87 KB

I did some testing today and can provide good news:

  1. the class is added to every menu item
  2. the added !empty() in the mentioned line is working fine! The classes are still added

So the fix could be (see attached patch file):

function responsive_menu_responsive_menu_off_canvas_tree_alter(array &$menu) {
  // Iterate over the top level of menu items and call the recursive function
  // which adds a unique class to each item and it's children.
+  if (!empty($menu['#items'])) {
    foreach ($menu['#items'] as &$item) {
      responsive_menu_off_canvas_add_class($item);
    }
+  }
}
dbielke1986’s picture

StatusFileSize
new39.11 KB
tanc’s picture

Excellent! I’ll see if I can give this patch a test later tonight. Thanks so much for the contribution!

dbielke1986’s picture

Excellent! I’ll see if I can give this patch a test later tonight. Thanks so much for the contribution!

It was a pleasure for me - such a quick response is gorgeous!!!

tanc’s picture

Hi @JD_1 I'm just testing the patch but it looks like it's been diff'd from an earlier version as it includes code already in 4.4.x. Are you able to create the patch from version 4.4.x please? Thanks!

dbielke1986’s picture

StatusFileSize
new614 bytes

Good Morning @tanc,

yes, you are right. This would be the patch for the issue #2826484 and 4.3.x.
Attached you will find the correct one for 4.4.x.

Hope this is working for you!

dbielke1986’s picture

dbielke1986’s picture

StatusFileSize
new629 bytes

Sorry... the first patch was a local diff. :-( This should be a good one.

dbielke1986’s picture

Hide Patch 1

wgsimon’s picture

This fixes it for me. Thanks.

nelo_drup’s picture

Title: Warning: Invalid argument supplied for foreach() in responsive_menu_responsive_menu_off_canvas_tree_alter() (line 237 of /var/www/html/swportl/web/modules/contrib/responsive_menu/responsive_menu.module) » Advertencia: Argumento no válido suministrado para foreach() en responsive_menu_responsive_menu_off_canvas_tree_alter() (línea 237 de /var/www/html/swportl/web/modules/contrib/responsive_menu/responsive_menu.module)

Problem pacth error: corrupt patch at line 17

dbielke1986’s picture

Title: Advertencia: Argumento no válido suministrado para foreach() en responsive_menu_responsive_menu_off_canvas_tree_alter() (línea 237 de /var/www/html/swportl/web/modules/contrib/responsive_menu/responsive_menu.module) » Warning: Invalid argument supplied for foreach() in responsive_menu_responsive_menu_off_canvas_tree_alter() (line 237 of /var/www/html/swportl/web/modules/contrib/responsive_menu/responsive_menu.module)
dbielke1986’s picture

StatusFileSize
new627 bytes

I just removed the empty line 17 from the patch..

dbielke1986’s picture

StatusFileSize
new628 bytes

Last try - don´t know why this line should be corrupt. If you can see the reason for that - feel free ti fix this. The patch itself is working for me and others, too.

tanc’s picture

StatusFileSize
new1.21 KB

I'm back from holiday now :)

This test attached should FAIL, proving there is a problem. The next patch will include the fix and should PASS!

tanc’s picture

Title: Warning: Invalid argument supplied for foreach() in responsive_menu_responsive_menu_off_canvas_tree_alter() (line 237 of /var/www/html/swportl/web/modules/contrib/responsive_menu/responsive_menu.module) » Warning thrown when menu specified does not exist

Updated unwieldy issue title

tanc’s picture

Version: 4.4.0 » 4.4.x-dev
StatusFileSize
new1.18 KB

Oops, messed up the test, this should work (fail).

tanc’s picture

Status: Active » Needs review
StatusFileSize
new1.84 KB

And this one should pass as it includes the fix.

tanc’s picture

Except I forgot Nightwatch tests don't seem to work on D9... so selecting other custom test scenarios...

  • tanc committed 466b681 on 4.4.x
    Issue #3168579 by JD_1, tanc: Warning thrown when menu specified does...
tanc’s picture

Status: Needs review » Fixed

ok, all good, although tests in #22 aren't reporting as failed, even though they have, which is what we want. Test in #23 passes which is also what we want. Committed and thanks!

Status: Fixed » Closed (fixed)

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