Media_entity_file_replace does not work within the linkit field

Created on 3 May 2023, about 2 years ago

Problem/Motivation

If you do /document/[number] the linkit field will get saved as /media/[number]

Steps to reproduce

Install the media_entity_file_replace module and try to use linkit to add it to the page.

Proposed resolution

Use the technique that linkit 6.0.0-beta4 had. That one saves correctly and take into consideration the alias that /document/ generates.

πŸ› Bug report
Status

Active

Version

6.1

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States bernardm28 Tennessee

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @bernardm28
  • πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson

    Thanks for reporting this. This does seem to overlap somewhat with an issue that was fixed in the development branch and has not been released. Can you confirm that the fix in πŸ› Linkit for Link field: Files displayed in link widget form should show full path Fixed does not resolve this issue for you?

  • πŸ‡ΊπŸ‡ΈUnited States bernardm28 Tennessee
  • πŸ‡ΊπŸ‡ΈUnited States bernardm28 Tennessee


    Here is a video of the issue.
    If you add both modules.

    • "drupal/media_entity_file_redirect": "^1.0@beta"
    • "drupal/linkit": "dev-6.0.x",

    On a vanilla Drupal 9.5 install. Once document is saved after clicking the edit feature it will go back to /media/ and try to save that instead.
    I did it on a content type field but a similar issue is found inside of layout builder blocks.

  • πŸ‡ΊπŸ‡ΈUnited States bernardm28 Tennessee

    I must add I was expecting the field to be able to save /document/1 as the the canonical url for that as that has a different behavior by skipping the media page and going straight to the pdf.

  • πŸ‡ΊπŸ‡ΈUnited States bernardm28 Tennessee
  • πŸ‡ΊπŸ‡ΈUnited States bernardm28 Tennessee
  • πŸ‡ΊπŸ‡ΈUnited States bernardm28 Tennessee
  • πŸ‡ΊπŸ‡ΈUnited States bkosborne New Jersey, USA

    We came across this as well.

    If the Media Entity File Redirect module (which I made) just modified the canonical path of media entities to be /download/[id], everything would just work. The reason the module doesn't do that is that the redirect route is optionally enabled per media type, and I don't think we can override the canonical link template per-bundle. It's the whole entity type. So instead, the module simply provides a route for the redirect path and provides LinkIt matcher and substitution plugins.

    One possibility is to have LinkIt detect if Media Entity File Redirect is enabled, and if so, check if it's enabled on the entities type. This seems messy to me. I think it's best to avoid having one contrib module have feature detection of other contrib modules.

    Another possibility is to fire an alter hook for the default value in the field widget? Media Entity File Redirect could then implement the hook and set the correct default value.

    Without such a hook, the module would need to alter the field widget via media_entity_file_redirect_field_widget_single_element_linkit_form_alter, which may work. I'll investigate that.

  • πŸ‡ΊπŸ‡ΈUnited States bkosborne New Jersey, USA

    Moving this issue to Media Entity File Redirect. I think that's the best place to solve this.

  • @bkosborne opened merge request.
  • πŸ‡ΊπŸ‡ΈUnited States bkosborne New Jersey, USA
Production build 0.71.5 2024