Argument #1 ($elements) must be of type array, null given, called in core layout_discovery.module

Created on 31 January 2024, 10 months ago
Updated 9 June 2024, 5 months ago

Problem/Motivation

Error met,

The website encountered an unexpected error. Try again later.
TypeError: Drupal\Core\Render\Element::children(): Argument #1 ($elements) must be of type array, null given, called 
in /web/core/modules/layout_discovery/layout_discovery.module on line 45 in Drupal\Core\Render\Element::children() 
(line 72 of core/lib/Drupal/Core/Render/Element.php).
template_preprocess_layout()
call_user_func_array() (Line: 261)
Drupal\Core\Theme\ThemeManager->render() (Line: 480)
Drupal\Core\Render\Renderer->doRender() (Line: 240)
Drupal\Core\Render\Renderer->render() (Line: 475)
Drupal\Core\Template\TwigExtension->escapeFilter() (Line: 125)
__TwigTemplate_8f6677c23a6d65de338b6ae8876df912->doDisplay() (Line: 394)
Twig\Template->displayWithErrorHandling() (Line: 367)
Twig\Template->display() (Line: 379)
Twig\Template->render() (Line: 38)
Twig\TemplateWrapper->render() (Line: 39)
twig_render_template() (Line: 348)

The corresponding code in modules/layout_discovery/layout_discovery.module is

  // Create an attributes variable for each region.
  foreach (Element::children($variables['content']) as $name) {
    if (!isset($variables['content'][$name]['#attributes'])) {
      $variables['content'][$name]['#attributes'] = [];
    }
    $variables['region_attributes'][$name] = new Attribute($variables['content'][$name]['#attributes']);
  }

Steps to reproduce

Proposed resolution

Change to,

  if (isset($variables['content'])) {
    foreach (Element::children($variables['content']) as $name) {
      if (!isset($variables['content'][$name]['#attributes'])) {
        $variables['content'][$name]['#attributes'] = [];
      }
      $variables['region_attributes'][$name] = new Attribute($variables['content'][$name]['#attributes']);
    }
  }

Merge request link

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

πŸ› Bug report
Status

Postponed: needs info

Version

11.0 πŸ”₯

Component
Layout discoveryΒ  β†’

Last updated 5 months ago

No maintainer
Created by

πŸ‡«πŸ‡·France Chris64 France

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

  • Issue created by @Chris64
  • πŸ‡«πŸ‡·France Chris64 France
  • Status changed to Needs review 10 months ago
  • πŸ‡«πŸ‡·France Chris64 France
  • Status changed to Active 10 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Don't see anything to review.

    But will need steps to reproduce this issue.

    Will also have to do some research about why that variable is empty, hopefully the steps help with that. Usually just putting an isset() could be masking a larger issue

  • Status changed to Postponed: needs info 9 months ago
  • πŸ‡«πŸ‡·France Chris64 France

    Usually just putting an isset() could be masking a larger issue

    Agree with this principle. And the other part.

    Original code reinstalled. But the problem does not happen any where. Therefore not possible for me actually to get more information about the issue...

  • πŸ‡¨πŸ‡­Switzerland saschaeggi Zurich

    This happens to me as well on 11.x-dev and the proposed solution seems to fix the problem

  • πŸ‡ͺπŸ‡ΈSpain marcoscano Barcelona, Spain

    I was kind of able to reproduce this by installing the Minimal profile, then applying a recipe that enabled gin + gin_toolbar + navigation (and imported config '*' from the navigation module).

  • πŸ‡¨πŸ‡¦Canada laura.j.johnson@gmail.com Toronto

    I am also running into this by installing the Minimal profile and then applying a recipe that enables gin + gin_toolbar + navigation and importing config '*' from the navigation module.

  • πŸ‡¬πŸ‡§United Kingdom dakala Fairford, Glos

    Same setup here - minimal profile, recipe with gin etc. Until this morning, everything was fine. Then I noticed I'd been using the dev version of gin, so I upgraded to the RC. Immediately, my site was broken with the error in this issue. A search for the error brought me here. When I reverted back to the dev version of gin, the error was gone. Perhaps gin is the source of this?

Production build 0.71.5 2024