Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
When Substitution type "Direct URL to media file entity" is selected we should add the option to add a download attributte so the file can be downloaded.
Make sure to enable the option here: https://www.drupal.org/files/issues/linkit-doc-media-matcher-config.png
Comment | File | Size | Author |
---|---|---|---|
#31 | 2997546_31.patch | 8.89 KB | Jelle_S |
#28 | notice-fix.patch | 978 bytes | tarik.cipix |
#17 | 2997546_17.patch | 8.79 KB | mpp |
#10 | 2997546_10.patch | 8.78 KB | mpp |
#7 | 2997546-7.patch | 8.14 KB | mpp |
Comments
Comment #2
mpp CreditAttribution: mpp at AmeXio for District09 commentedComment #3
mpp CreditAttribution: mpp at AmeXio for District09 commentedComment #5
mpp CreditAttribution: mpp at AmeXio for District09 commentedUpdated tests.
Comment #7
mpp CreditAttribution: mpp at AmeXio for District09 commentedComment #8
mpp CreditAttribution: mpp at AmeXio for District09 commentedComment #9
Jérôme DehorterHi mpp,
Your patch works on D8.6.1 / Linkit 5.0-beta7. Thanks for that.
Next step if possible, add the title to file name in download attribute instead of download.
P.S. : Don't forget in the Readme : Check the option in Linkit URL converter option
Comment #10
mpp CreditAttribution: mpp at AmeXio for District09 commentedHi Jérôme Dehorter, welcome & thanks for the feedback.
I added the documentation to the README.
Interesting remark about the download title but if we use the title, we'd need to escape the filename to a valid and secure name. It would probably be better to use the Media's source_field's url?
Comment #11
Jérôme DehorterHi mpp,
Thanks for this new patch. I test it quickly and I give you a new feedback soon.
Comment #12
a-fro CreditAttribution: a-fro commentedThe patch was succeeding but the code was throwing an error because $settings['download'] was undefined when attempting to get the #default_value. This patch fixes that issue for me, in 8.6.2.
Comment #13
anonLooks good. I would like some more information about the "download" attribute but I can't find any.
Where can I read or see this?
Comment #14
guedressel CreditAttribution: guedressel at CYLEDGE commentedPlease take the module media_entity_download into account. It handles download of media more robust by creating a proxy URL for files. Major benefit: Media download links become predictable and don't change if a media source file gets replaced and therefore changes the file URL. Also access checks are in the make to honor publishing workflow for media entities (as well as private files permission checks).
Comment #15
mpp CreditAttribution: mpp at AmeXio for District09 commented@guedressel, thank you for highlighting media_entity_download.
Using the proxy URL makes sense to facilitate the download and to work around any caching issues that might arise from changing urls but it's not a good SEO practice.
Before I close this issue I want to make sure that media_entity_download is using the media entity alias instead of the proxy url.
Comment #16
mpp CreditAttribution: mpp at AmeXio for District09 commented@anon,
When used on an anchor, this attribute signifies that the browser should download the resource the anchor points to rather than navigate to it.
See documentation on the download attribute.
Perhaps we can make the value for download attribute configurable in a follow up issue so a webmaster can configure a media field to use for the download filename?
Comment #17
mpp CreditAttribution: mpp at AmeXio for District09 commentedAdded the entity label instead of 'download' so the downloaded document is named as such.
Comment #18
ducktape CreditAttribution: ducktape at District09 commentedNice, thanks for the patch @mpp. Works well on our test environment.
Comment #19
anonGreat work! Thanks for the patch.
Comment #21
joewhitsittThanks for working on this. I thought I had everything correctly configured, however the download attribute seems to be populated with the file's media_field_data "name" value.
<a data-entity-substitution="media" data-entity-type="media" data-entity-uuid="fb415703-ba62-4256-aecb-61d64c8c4151" href="/media/17" download="demo txt" title="demo txt">/media/17</a>
The URI is: public://2019-06/demo.txt
We are requiring users to provide a name on upload and this doesn't always match the filename.
Is this working by design and we need to auto-populate/disable the name field with the filename for this to work?
Comment #22
BerdirI'd say that's a bug. The problem is that the logic for this is outside of the media plugin, because the substitution plugin doesn't have the ability to return that information, so it is hardcoded outside.
Two ideas:
1) Add a method specifically for Media that we can call there, so at least the logic is where it belongs, would still be hardcoded.
2) Introduce an Interface SubstitutionUrlAlter or something, with a method like $substitution->alterUrl($element) (a bit strange naming..).
Then alternative implementations could do something like that, we could even have the configuration on the substitution plugin where I'd say it belongs instead of the filter format (where you might need to configure it 3x for different text formats), it would even allow to have different profiles that add the attribute and others that don't.
Comment #23
anonYes, this sounds like the way to go..
Comment #24
Berdir@anon: Do you want to revert this or create a follow-up? Might be a bit weird if we move the settings around in a follow-up?
Comment #25
anon@Berdir: I can revert this later today. This fix is only in the dev branch anyway.
Comment #27
anonReverted now.
Comment #28
tarik.cipix CreditAttribution: tarik.cipix commentedPlease add this patch to fix a notice.. it's filling up the recent log messages.
Comment #29
alisonComment #30
Jelle_SRerolled #17 since it worked for our use case, but I'll keep the issue on "Needs work" since it obviously still has some issues.
Comment #31
Jelle_SIf only I had made the patch correctly... sorry for the spam
Comment #32
Fernly CreditAttribution: Fernly at Dropsolid for District09 commentedI am under the impression that the latest patch #31 to fix the notice is already included in 6.x. Setting this issue to RTBC. Perhaps others can confirm this before closing this issue.
Comment #34
Fernly CreditAttribution: Fernly at Dropsolid for District09 commentedI would recommend the maintainer to close this issue if confirmed that the fix is included in 6.x. The failing patch does not need to be merged anymore.