file - allow change link options in preprocess / twig for target blank etc

Created on 6 December 2017, about 7 years ago
Updated 8 June 2023, over 1 year ago

Hello,

I want change link options about attributes in core function template_preprocess_file_link.
Now I can't add "target='_blank'" option from $variables, in my theme preprocess function.

What you say?
Can I send patch for it?

💬 Support request
Status

Closed: works as designed

Version

9.5

Component
File system 

Last updated about 13 hours ago

Created by

🇨🇿Czech Republic landsman

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.

  • 🇳🇱Netherlands tinto Amsterdam

    Thanks for creating this issue and providing a patch, @landsman.

    The patch provided in #3 may well solve the requirement in your particular case, but I don't think it would be appropriate to add a target="_blank" to all file links for all Drupal users.

    To answer the question posed in this issue title, my guess is that there are several ways to achieve the required functionality. For example, you could copy file-link.html.twig to your custom theme and add a link attribute as follows:

    <span{{ attributes }}>{{ icon }} {{ link|merge({'#attributes': {'target': '_blank'}}) }}</span>
    

    This should open all file links in your frontend theme in a new tab. Hope this helps.

    I'm changing the category for this issue to support request and marking it as closed for now. If anyone wants to discuss further, or knows a better/different approach to achieve the OP's objective, feel free to add your comments below.

Production build 0.71.5 2024