Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By samuel.mortenson on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.4.x
Introduced in version:
9.4.0-alpha1
Issue links:
Description:
The html_tag render element now supports render array nesting, similar to how arrays are nested under container elements.
Before
Previously the html_tag only accepted markup in its #value property, which meant you had to pass a string or pre-render markup.
$rect = [
'#type' => 'html_tag',
'#tag' => 'rect',
'#attributes' => [
'width' => 50,
'height' => 50,
'style' => 'fill:rgb(0,0,255)',
],
];
$svg = [
'#type' => 'html_tag',
'#tag' => 'svg',
'#value' => render($rect)
];
After
Now you can nest render arrays under an html_tag, allowing more complex structures.
$svg = [
'#type' => 'html_tag',
'#tag' => 'svg',
[
'#type' => 'html_tag',
'#tag' => 'rect',
'#attributes' => [
'width' => 50,
'height' => 50,
'style' => 'fill:rgb(0,0,255)',
],
],
];
Impacts:
Module developers
Themers
Comments
D7 backport
Here's the link to the D7 backport: https://www.drupal.org/project/drupal/issues/2981726
-Pol-
https://not-a-number.io/