Problem/Motivation
I have a menu that has a single level of links and I am getting a fair number of PHP warnings on the page.
Issue 1
Notice: Undefined index: below in Drupal\menu_item_extras\Service\MenuLinkTreeHandler->processMenuLinkTree() (line 154 of modules/contrib/menu_item_extras/src/Service/MenuLinkTreeHandler.php).
Issue 2
Notice: Undefined offset: 0 in menu_item_extras_theme_suggestions_menu_levels() (line 216 of modules/contrib/menu_item_extras/menu_item_extras.module).
Proposed resolution
Issue 1 can be resolved by updating the if check for if ($item['below']) to if (isset($item['below'])) in src/Service/MenuLinkTreeHandler.php. However, this causes issue 2.
Similarly issue 2 can be resolved by simply checking to make sure that the $children array is there before trying to use $children[0] in menu_item_extras.module.
Comments
Comment #2
mikemadison commentedComment #3
mikemadison commentedComment #5
mikemadison commentedComment #6
mikemadison commentedComment #7
mikemadison commentedComment #8
ozinHi @mikemadison, thanks for the patch. What do you think if we will use `!empty()` instead of `isset()`, it will not throw the errors and check what we need?
Comment #9
jmarcou commentedActually I think it's better to use
!empty()as the previous code was checking if the variable was equivalent to true, but didn't checked if the variable was set before, and the equivalent ofisset($item['below']) && $item['below']is!empty($item['below']).Here is the updated patch.
Comment #11
ozin