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

  1. Have a Drupal site with drupal/dashboard ^2 installed.
  2. Have at least one Dashboard config entity where a section component's
    additional key is NULL or absent in the stored YAML.
  3. Load any page that triggers the Navigation block (almost every page when
    using Gin or Navigation themes).
  4. 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

Command icon 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

aolvera created an issue. See original summary.

penyaskito’s picture

The fix is harmless, wondering if we could have a test reproducing this problem though.

penyaskito’s picture

Category: Bug report » Support request
Priority: Critical » Normal

On second thought, I've checked and $additional has been in LB forever (since introduced as experimental in 8.5.0). In its config schema:

    additional:
      type: ignore
      label: 'Additional data'

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.

penyaskito’s picture

Status: Active » Postponed (maintainer needs more info)