By joelpittet on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.1.x
Introduced in version:
8.1.x
Issue links:
Description:
Providing indexed instead of associative array of class would produce an unexpected class="_" in markup of links.html.twig. Resolved this by moving the class generation to Stable's preprocess.
Renderable array for links.html.twig
- Indexed array
-
$build['links'] = [ '#theme' => 'links', '#links' => [ ['title' => 'Block', 'url' => '/admin/help/block'], ['title' => 'Breakpoint', 'url' => '/admin/help/breakpoint'], ]; - Associative array
-
$build['links'] = [ '#theme' => 'links', '#links' => [ 'block' => ['title' => 'Block', 'url' => '/admin/help/block'], 'breakpoint' =>['title' => 'Breakpoint', 'url' => '/admin/help/breakpoint'], ];
Before
- Indexed array
-
<ul class="links"> <li class="_"><a href="/admin/help/block">Block</a></li> <li class="_"><a href="/admin/help/breakpoint">Breakpoint</a></li> </ul> - Associative array
-
<ul class="links"> <li class="block"><a href="/admin/help/block">Block</a></li> <li class="breakpoint"><a href="/admin/help/breakpoint">Breakpoint</a></li> </ul>
After
- Indexed array
-
<ul class="links"> <li><a href="/admin/help/block">Block</a></li> <li><a href="/admin/help/breakpoint">Breakpoint</a></li> </ul> - Associative array
-
<ul class="links"> <li><a href="/admin/help/block">Block</a></li> <li><a href="/admin/help/breakpoint">Breakpoint</a></li> </ul>
Regarding Stark/Core and users of base theme: false
If you are using base theme: false. And need this feature, please copy the preprocess theme hook from stable into your theme.
/**
* Implements template_preprocess_links().
*/
function THEME_preprocess_links(&$variables) {
if (!empty($variables['links'])) {
foreach ($variables['links'] as $key => $value) {
if (!is_numeric($key)) {
$class = Html::getClass($key);
$variables['links'][$key]['attributes']->addClass($class);
}
}
}
}
Impacts:
Module developers
Themers