function ThemeTest::testAttributeMerging
Same name in other branches
- 9 core/modules/system/tests/src/Kernel/Theme/ThemeTest.php \Drupal\Tests\system\Kernel\Theme\ThemeTest::testAttributeMerging()
- 8.9.x core/modules/system/tests/src/Kernel/Theme/ThemeTest.php \Drupal\Tests\system\Kernel\Theme\ThemeTest::testAttributeMerging()
- 11.x core/modules/system/tests/src/Kernel/Theme/ThemeTest.php \Drupal\Tests\system\Kernel\Theme\ThemeTest::testAttributeMerging()
Tests attribute merging.
Render arrays that use a render element and templates (and hence call template_preprocess()) must ensure the attributes at different occasions are all merged correctly:
- $variables['attributes'] as passed in to the theme hook implementation.
- the render element's #attributes
- any attributes set in the template's preprocessing function
File
-
core/
modules/ system/ tests/ src/ Kernel/ Theme/ ThemeTest.php, line 40
Class
- ThemeTest
- Tests low-level theme functions.
Namespace
Drupal\Tests\system\Kernel\ThemeCode
public function testAttributeMerging() : void {
$theme_test_render_element = [
'elements' => [
'#attributes' => [
'data-foo' => 'bar',
],
],
'attributes' => [
'id' => 'some_attribute',
],
];
$this->assertThemeOutput('theme_test_render_element', $theme_test_render_element, '<div id="some_attribute" data-foo="bar" data-variables-are-preprocessed></div>' . "\n");
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.