Link render element overwrites CSS class

Created on 14 December 2024, about 1 month ago

Problem/Motivation

The Link render element supports supplying attributes both in $element['#attributes'] and $element['#options']['attributes']. These are combined with an array + operator, which does not combine classes when they are present in both array elements.

Steps to reproduce

The Twig extension add_class() sets the class in the #attributes. For a link, there may already be a class in the #options. This happens in radix v6 for local tasks and is exhibited when viewing a page which is a secondary local task. The primary local task has a class of "is-active" and radix adds classes "nav-link" and "active", which fails.

1. Install Radix v6.
2. Create a page with primary and secondary local tasks.
3. Visit the page with the secondary local task.
4. Notice that the primary task tab is display incorrectly and contains only the "is-active" class.

Obviously there are much simpler ways to reproduce this but this is the one I know of without creating a custom module to demonstrate it.

Proposed resolution

Merge the classes in this situation.

πŸ› Bug report
Status

Active

Version

11.1 πŸ”₯

Component

render system

Created by

πŸ‡ΊπŸ‡ΈUnited States danchadwick Boston

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024