Skip to content
Snippets Groups Projects
Commit 85939fc6 authored by Mikael Meulle's avatar Mikael Meulle
Browse files

Issue #3495982 by just_like_good_vibes, grimreaper: Not possible to display a...

Issue #3495982 by just_like_good_vibes, grimreaper: Not possible to display a comment field in Layout Builder
parent fd238fef
Branches 2.0.x
Tags
No related merge requests found
......@@ -36,7 +36,28 @@ class SlotPropType extends PropTypePluginBase {
if (is_string($value)) {
return ['#children' => Markup::create($value)];
}
if (is_array($value) && empty(Element::properties($value))) {
if (!is_array($value)) {
return empty($value) ? ['#cache' => []] : ['#plain_text' => (string) $value];
}
return self::cleanRenderArray($value);
}
/**
* Clean a render array.
*
* @param array $value
* The render array to clean.
*
* @return array
* The cleaned render array.
*/
protected static function cleanRenderArray(array $value): mixed {
if (empty($value)) {
// Element::isRenderArray() returns FALSE for empty arrays.
return ['#cache' => []];
}
$element_properties = Element::properties($value);
if (empty($element_properties)) {
// Twig `is sequence` and `is mapping `tests are not useful when a list
// of renderables has mapping keys (non consecutive, strings) instead of
// sequence (integer, consecutive) keys. For example a list of blocks
......@@ -44,6 +65,11 @@ class SlotPropType extends PropTypePluginBase {
// So, transform this list of renderables to a proper Twig sequence.
return array_map(static fn($item) => self::normalize($item), array_is_list($value) ? $value : array_values($value));
}
foreach ($value as $key => & $item) {
if (!in_array($key, $element_properties, TRUE)) {
$item = self::normalize($item);
}
}
return $value;
}
......
......
......@@ -41,7 +41,7 @@ class SlotPropTypeTest extends PropTypeNormalizationTestBase {
*/
public static function normalizationTests() : array {
return [
"null value" => [NULL, NULL],
"null value" => [NULL, ["#cache" => []]],
];
}
......@@ -68,6 +68,10 @@ class SlotPropTypeTest extends PropTypeNormalizationTestBase {
["b" => ["#weight" => 2, "#markup" => "slot"], "a" => ["#weight" => 1, "#markup" => "my "]],
"my slot",
],
"render array special" => [
[0 => ["#markup" => "my slot", "randomKey" => []]],
"my slot",
],
];
}
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment