Direct Link to File in Media Entity Document

Created on 27 November 2017, about 7 years ago
Updated 17 March 2023, almost 2 years ago

Hi

I have created a Document Media Entity Bundle using media_entity_document Version: 8.x-1.1.

The bundle has a single File field in it

I would like the ability to link directly to the file instead of the media entity.

I found this https://www.drupal.org/node/2866525 β†’ commit and have setup my Linkit profile and html filters as documented.

Problem is, when I create a link, it still links to the media entity URL (e.g. /media/6) instead of the direct URL of the file in contains.

Am I missing something?

Thanks
Daniel

πŸ’¬ Support request
Status

Fixed

Version

7.0

Component

Code

Created by

πŸ‡¦πŸ‡ΊAustralia danjordan

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.

  • πŸ‡¦πŸ‡ΊAustralia timfletcher

    True @Steve - Drupal picks up the data-entity-substitution attribute and processes it when the page is saved and the filters are processed.

    If the value is 'canonical', it points to the Media entity. If you replace it with 'media', it points to to the file.

    You could do a bulk Find and Replace (carefully) to save the pain of finding and replacing all your media links.

  • πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson

    Worth noting that you need to set this up first before adding your links as media items. Content added prior will not update automatically

    I wrote up ✨ Previously created media URLs should update if the matcher is changed from canonical to direct URL Active to raise the question of whether media entity URLs should be updated retroactively. I'm not sure it *should*, but we can think about it!

  • πŸ‡ΊπŸ‡¦Ukraine ruslan piskarov Kyiv, Ukraine

    Is this issue again in 6.1.4 and 7.0.0-alpha1 or did I miss something?
    With "Direct URL to media file entity" option I see an URL like media/XXX.

  • πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson

    Is this issue again in 6.1.4 and 7.0.0-alpha1 or did I miss something?
    With "Direct URL to media file entity" option I see an URL like media/XXX.

    I just functionally tested both 6.1.4 and the latest commit on the 7.x branch, and in both cases, the resulting rendered link to the media entity does go, as expected, to the media file (e.g., sites/default/files). To be clear, the source code in CKEditor will show media/XXX as in the following example, but when rendered, it does provide the link to the filesystem.

        <a href="/media/1" data-entity-type="media" data-entity-uuid="263229c1-f780-4d65-a09e-9c401342caa6" data-entity-substitution="media">test</a>
    

    If data-entity-substitution="canonical", it will render /media/XXX, but if data-entity-substitution="media" it will render the direct link.

    Documentation about this is at https://www.drupal.org/docs/extending-drupal/contributed-modules/contrib... β†’

    @ruslan, let me know if that doesn't answer your question correctly.

  • πŸ‡ΊπŸ‡¦Ukraine ruslan piskarov Kyiv, Ukraine

    Thank you, @mark_fullmer, for your reply.
    I am looking again.

    A fresh D10 site enabled the Linkit module v 7.0.0-alpha1 and media macher.
    Create two media 1.jpg and 2.png.
    In CKeditor
    Create a node with "Text Link" text and two images (one image inserted as media, one uploaded as file).
    Link all elements to "2.png" media.

    A source code will be

    <p>
        <a href="/media/4" data-entity-type="media" data-entity-uuid="2142ef3f-60e0-4115-80ce-8d460aa5406a" data-entity-substitution="media">Text Link</a>
    </p>
    <a href="/media/4"><drupal-media data-entity-type="media" data-entity-uuid="c390e8a9-0b66-4c44-8bd3-dd79b95d4c65">&nbsp;</drupal-media></a>
    <a href="/media/4"><img src="/sites/default/files/inline-images/3.jpg" data-entity-uuid="3d311f2c-0dad-4ef6-a1ec-949d0c069523" data-entity-type="file" width="1800" height="943"></a>

    Rendered HTML will be

    <p>
      <a href="/sites/default/files/2024-11/2.pdf" 
         data-entity-type="media"  
         data-entity-uuid="2142ef3f-60e0-4115-80ce-8d460aa5406a" 
         data-entity-substitution="media" title="2.pdf">Text Link</a>
    </p>
    <a href="/media/4">
      <div class="media media--type-image media--view-mode-default">
        <div class="field field--name-field-media-image field--type-image field--label-visually_hidden">
          <div class="field__label visually-hidden">Image</div>
          <div class="field__item">
            <img loading="lazy" src="/sites/default/files/styles/large/public/2024-11/1.jpg.webp?itok=5BbDYn1H"
                                        width="480" height="251" alt="test">
          </div>
        </div>
      </div>
    </a>
    <a href="/media/4">
      <img data-entity-uuid="3d311f2c-0dad-4ef6-a1ec-949d0c069523" 
           data-entity-type="file"
           src="/sites/default/files/inline-images/3.jpg" width="1800" height="943"
                                loading="lazy">
    </a>

    So, it works nicely with texts but has media issues.

  • πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson

    Thanks for the further testing, @ruslan_piskarov. I think you're pointing out a specific issue with links wrapping media, which is described in the Linkit issue at πŸ’¬ Links surrounding Media Library item strips data-entity-type and data-entity-uuid Postponed , and has been traced back to core issue ✨ Drastically improve the linking experience in CKEditor 5 Needs work . If that sounds right to you, then I think this issue -- the direct media option -- is still "works as designed" and can remain closed without further work.

  • πŸ‡ΊπŸ‡¦Ukraine ruslan piskarov Kyiv, Ukraine

    @mark_fullmer, you are right. I didn't see #3317769 before. Thank you very much for the quick response, and have a tremendous day.

Production build 0.71.5 2024