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

mikemadison created an issue. See original summary.

mikemadison’s picture

StatusFileSize
new1.2 KB
mikemadison’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 2: php-warnings-no-children-3014364-2.patch, failed testing. View results

mikemadison’s picture

mikemadison’s picture

Status: Needs work » Needs review
mikemadison’s picture

StatusFileSize
new1.2 KB
ozin’s picture

Hi @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?

jmarcou’s picture

StatusFileSize
new1.2 KB

Actually 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 of isset($item['below']) && $item['below'] is !empty($item['below']).

Here is the updated patch.

  • ozin committed 250186e on 8.x-2.x authored by jmarcou
    Issue #3014364 by mikemadison, jmarcou: PHP Warnings for Single Level...
ozin’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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