Work with media file field

Created on 29 September 2020, about 4 years ago
Updated 9 December 2023, 11 months ago

Copying issue from issue #2128931: Work with media file field for 7, because in 8 is the same .

This would be lovely to work with the Media file field. I'm currently have to use views if I just want to output one image from my multi-value media fields.

Media requires a Rendered file formatter, so it would need to piggy back on that, or be a Media File formatter.

Just hoping...

Feature request
Status

Fixed

Version

1.0

Component

Code

Created by

🇪🇸Spain aleix

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.

  • 🇫🇷France mitsuko

    Update the patch for drupal 10 compatibility

  • Status changed to Needs work over 1 year ago
  • 🇫🇷France fgm Paris, France

    @mitsuko: could you apply that patch to the existing MR at https://git.drupalcode.org/issue/image_delta_formatter-3173945/-/tree/31... ? As it stands, the current MR does not include D10 support.

    Also, more importantly, I think there is no reason to have separate modules to support that use case: we could just as well have the two plugins in the same module, and spare the extra load for an additional module.

    In addition, since both plugins ultimately derive from the same underlying ImageFormatter (via MediaThumbnailFormatter in the case of image_delta_formatter_media), it would make sense to just reuse the code instead of duplicating it. One possibility would be to defined a Trait holding that common code, and reduce both plugins to one-liners using that trait.

  • 🇳🇱Netherlands neograph734 Netherlands

    Also, more importantly, I think there is no reason to have separate modules to support that use case: we could just as well have the two plugins in the same module, and spare the extra load for an additional module.

    Please also check comment #7. It is split because of the dependency on the media module.

  • Status changed to Needs review over 1 year ago
  • 🇫🇷France fgm Paris, France

    @neogrpah734 indeed, since media is a core module and has all but replaced image module for most common use cases since Drupal 8.4, I do not consider the dependency on media to be an issue any longer: this is no longer 2021.

    I just pushed a combined version on the MR, which also drop D8 support since it has been unsupported for almost 3 years already: comments welcome.

  • 🇫🇷France fgm Paris, France

    In patch form in case anyone prefers that.

  • 🇫🇷France fgm Paris, France
  • Status changed to Needs work over 1 year ago
  • 🇫🇷France fgm Paris, France

    With the added dependency, the code is now missing a hook_update_N to enabled media if needed.

  • Status changed to Needs review over 1 year ago
  • 🇫🇷France fgm Paris, France

    Added hook_update_N.

  • 🇫🇷France fgm Paris, France

    There was a typo in the media formatter name ("medial_delta_formatter").

    Regarding the conditional loading with isApplicable, it couldn't work because to call the method, the class first needs to be loaded and that will fail if media.module is not loaded.

    Another approach could be to compose the thumbnail formatter instead of inheriting from it, to support conditional loading, but it would make the code significantly more complex.

  • 🇨🇭Switzerland berdir Switzerland

    fgm credited Berdir .

  • 🇫🇷France fgm Paris, France

    @berdir suggested a smarter approach on Slack: the Media delta plugin is now conditional, which avoids both the extra submodule and depending on media.module and will still enable the Media formatter automatically if media is present.

    I guess that's a better choice for everyone ?

    • fgm committed 93bbc8d9 on 8.x-1.x authored by Mitsuko
      Issue #3173945 by fgm, Mitsuko, aleix, Berdir: Work with media file...
  • Status changed to Fixed over 1 year ago
  • 🇫🇷France fgm Paris, France

    Merged that simplified version to current dev HEAD, thanks everyone.

  • Automatically closed - issue fixed for 2 weeks with no activity.

  • Status changed to Fixed 11 months ago
  • 🇳🇱Netherlands neograph734 Netherlands

    @fgm thanks for all the work. Is there any chance you could create a tagged release with these changes included?

  • 🇫🇷France fgm Paris, France

    @Neograph734 the plan is to do it after D10.2 release, along with 📌 Update Drupal / PHP support Active . Think it's worth doing one before ?

  • 🇳🇱Netherlands neograph734 Netherlands

    Thanks for the fast reply! I believe that 10.2 is planned for next week or so? No need to create a new release now then.
    I was only asking because I figured that I was still on the dev version.

Production build 0.71.5 2024