Problem/Motivation
When visiting any page after installing or updating the Dashboard module, the
site throws a fatal TypeError:
TypeError: Drupal\layout_builder\SectionComponent::__construct(): Argument #4 ($additional) must be of type array, null given, called in web/modules/contrib/dashboard/src/DashboardStorageHandler.php on line 43
This happens because DashboardStorageHandler::mapFromStorageRecords()
passes $component['additional'] directly to the
SectionComponent constructor. When that key is missing or stored
as NULL in existing configuration (e.g. dashboards created before
the additional key was introduced), PHP 8 enforces the strict
array type hint and fatals.
Steps to reproduce
- Have a Drupal site with
drupal/dashboard ^2installed. - Have at least one Dashboard config entity where a section component's
additionalkey isNULLor absent in the stored YAML. - Load any page that triggers the Navigation block (almost every page when
using Gin or Navigation themes). - Observe the fatal
TypeError.
Proposed resolution
Use the null coalescing operator to fall back to an empty array when
$component['additional'] is NULL or not set:
- $component['additional'] + $component['additional'] ?? []
This is the same defensive pattern used by Drupal core's
Section::fromArray().
Remaining tasks
- Review and merge MR.
User interface changes
None.
API changes
None.
Data model changes
None.
Issue fork dashboard-3587305
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
penyaskitoThe fix is harmless, wondering if we could have a test reproducing this problem though.
Comment #4
penyaskitoOn second thought, I've checked and
$additionalhas been in LB forever (since introduced as experimental in 8.5.0). In its config schema:Which means their structure is not checked, but his existence is required. I think having a workaround for invalid schema is a no-go.
We should make config validation more strict, not more lax.
How was this triggered? The only why I can think of is a hand-crafted recipe.
Comment #5
penyaskito