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']);
}
}