template_preprocess_file_link() does not allow adding attributes to link element

Created on 16 November 2017, about 7 years ago
Updated 26 September 2024, about 2 months ago

I've noticed that the documentation on template_preprocess_file_link() includes:

array $variables: An associative array containing:
(...)
attributes: An associative array of attributes to be placed in the a tag.

(See: https://api.drupal.org/api/drupal/core%21modules%21file%21file.module/fu...)

However, the function actually initializes $options as an empty array, then sets some $options['attributes'] and passes that into the functions that generate the link markup.

If passed, the attributes in $variables['attributes'] are actually intended for the <span> that contains the file link - as seen in the default template, file-link.html.twig.
See: https://api.drupal.org/api/drupal/core%21modules%21file%21templates%21fi...

I'm guessing this was probably small documentation mistake, rather than a bug. I marked this as a feature request though, as it would be helpful to allow preprocess functions for this theme hook to provide attributes for the link element itself.

✨ Feature request
Status

Active

Version

11.0 πŸ”₯

Component

theme system

Created by

πŸ‡ΊπŸ‡ΈUnited States tea.time

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024