Warning: Undefined array key "display_empty"

Created on 14 March 2025, 19 days ago

Problem/Motivation

Since upgrading to 8.x-1.14 we get the following on all of our menu blocks:

Warning: Undefined array key "display_empty" in Drupal\menu_block\Plugin\Block\MenuBlock->blockAccess() (line 446 of /var/www/html/docroot/modules/contrib/menu_block/src/Plugin/Block/MenuBlock.php)

I traced it to this commit:

https://git.drupalcode.org/project/menu_block/-/commit/90df58d2d7e6de5bb7903aa43e9c555cb30e4c73

When adding a new option to plugin configuration, you cannot assume existing installs of the module have that configuration option set, since doing so would require re-saving every menu block. And yet the code introduced in that commit makes that assumption.

Steps to reproduce

Clear cache, then display a page with a menu block that was added using a previous release of the module.

Proposed resolution

Current code:

if (empty($build['#items']) && !$this->configuration['display_empty']) {

Fix:

if (empty($build['#items']) && !($this->configuration['display_empty'] ?? FALSE)) {

Remaining tasks

Create a MR with the change.

User interface changes

None

API changes

None

Data model changes

None

πŸ› Bug report
Status

Active

Version

1.14

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States john.oltman

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024