Follow-up issue from #2986967: Use Media name for the "Download Link" title where we discussed how to make the link title more flexible.
That issue was a bug report, this is a feature request to enhance functionality:
Wouldn't it perhaps be better to make the link formatter more flexible by adding options and perhaps work with media tokens instead of a hard coded solution? I don't think that there will be THAT ONE perfect link text.
Yes a selection sounds like a good option:
- Media title
- File name
- Description
- Perhaps a custom text option (translatable) would also make sense to have a custom link title. I think that's also needed in many cases.
Also we could add a checkbox to use the file description as title text for the link to provide flexibilty to use it as tooltip, etc... with minimal effort.
Let's discuss the demand for that here. In our case it would have helped a lot.
Comment | File | Size | Author |
---|---|---|---|
#11 | 3059830-make-link-title-11.patch | 2.64 KB | capysara |
Issue fork media_entity_download-3059830
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
AnybodyComment #3
lolcode CreditAttribution: lolcode commentedI took a pass at this using the approach of adding a theme function that receives the media object.
This makes it possible for site owners to add in whatever variables they like from the media object.
Comment #4
AnybodyHi @lolcode,
great work! That makes it a lot more flexible already, at least for theme developers. While I still think tokens would be additionally helpful for other cases and administrators, we should first focus on your approach.
That patch looks allright! Of course it would be best to add a test to ensure this patch doesn't change the markup for existing sites.
Thanks a lot so far.
What do you think about token support for the link title in the patch?
Comment #5
lolcode CreditAttribution: lolcode commentedI could attempt to add the code for some of the field formatter options as well.
One reason I did not is that it would clash with settings changes pending in this issue: https://www.drupal.org/project/media_entity_download/issues/3008834 while a theme function can be added independently.
I also realised that I forgot to add cache tags to the theme function. I have update the patch to include them.
The markup test is a good idea but would have to exist before this patch is applied therefore it would need to be a separate issue, merged first.
Comment #6
almunningsPatch super useful for document downloads.
{{ link|merge({'#title': media_entity.name.value }) }}
in a twig and happy!Comment #7
lolcode CreditAttribution: lolcode commentedSorry, I realise that I missed adding the staged files in the patch in #5. Here is one with the cache tags added that has all the files.
Comment #8
BerdirNeeds a reroll and a complete, combined patch.
Comment #11
capysara CreditAttribution: capysara at Bounteous commentedRerolled and combined #5 and #7. Created a merge request https://git.drupalcode.org/project/media_entity_download/-/merge_requests/1 and attached a patch file for review.
Comment #12
capysara CreditAttribution: capysara at Bounteous commentedComment #13
wrd CreditAttribution: wrd at State of Missouri, OA-ITSD commentedThis is working like a charm for me.
Comment #14
elgandoz CreditAttribution: elgandoz commented#11 works great on 8.x-2.1, thanks @capysara!
For reference I altered the button like this:
Comment #15
elgandoz CreditAttribution: elgandoz at Department of Customer Service, NSW commentedI'm unsure if this is off-topic, but the default media formatter for "documents" also prints the filetype and filesize alongside the title, eg. Media name (PDF, 12.3KB).
I added here a patch that adds those 2 variables in the template, since it could be a fairly common requirement (and also a good practice).
For reference: alternatively, this can also be done in the in your .theme file using a preprocess hook, without my attached patch:
Comment #16
robcarrThe patch at 11 works fine.
The patch at 15 is really helpful, but not necessarily relevant to this issue, and should be added to a fresh issue as a separate feature request.
Comment #17
bramvandenbulcke CreditAttribution: bramvandenbulcke commentedPatch #11 is working well. I'm using Drupal 10.2.5 at the moment.
Steps taken: