Problem/Motivation
The file linke itslef is being generated using \Drupal::l in template_preprocess_file_link() and therfore it is impossible to add attributes to the link itself.
Proposed resolution
Move the link generation to the twig template file-link.html.twig to be able to change attrinbutes on the link
Remaining tasks
- Figure out if this change makes sense
- Provide a patch
Comments
Comment #8
mecano commentedAny way we can access the link variable attributes, uri and title from file-link.html.twig?Comment #9
olarin commentedThe correct solution would be https://www.drupal.org/project/drupal/issues/2913487 - by changing it to a renderable array this would allow modules and themes to implement file_link preprocessors and add attributes to said render array. Links generally shouldn't be manually created in templates if it can be avoided.