Problem/Motivation

We used Layout Section Classes on few projects and didn't have any issues. But with last update to the latest core version the following warning appears:
Warning: Invalid argument supplied for foreach() in /var/www/html/docroot/core/lib/Drupal/Core/Render/Element/Checkboxes.php on line 100

The warning appears on the first attempt of the adding of new section with usage of layout section classes. Unfortunately this warning appears in ajax callback so it is currently impossible to add new section.

Steps to reproduce

Drupal Version 9.3.2
Layout Section Classes 8.x-1.1

Proposed resolution

The reason of the problem is that Checkboxes render element waits for the array as a default value.
Take a look on the code below (line 100 of Checkboxes.php):

...
      foreach ($element['#default_value'] as $key) {
        $value[$key] = $key;
      }
...

But ClassyLayout plugin sends NULL as initial value (line 69 of ClassyLayout):

$definition_default = $class_definition['default'] ?? NULL;

I presume the fix is very simple - replace NULL with [] as initial value in ClassyLayout.php.

Comments

nsavitsky created an issue. See original summary.

nsavitsky’s picture

larowlan’s picture

How are you adding checkboxes? The widget is #type select

nsavitsky’s picture

@larowlan Oh, my bad, you are right! We did use a patch from https://www.drupal.org/project/layout_section_classes/issues/3162758 and problem relates to it. I will provide extra patch in the ticket I mentioned and this ticket can be closed.

nsavitsky’s picture

Status: Active » Closed (works as designed)