It works with private images, not working with thumbnails

Created on 30 December 2023, 12 months ago
Updated 21 May 2024, 7 months ago

Problem/Motivation

This is a great module. How the hill did the core team not think of the display of a teaser having multiple medias ? That's why we need to have a more extensive usage of this module. I can confirm that, contrary of what is claimed in the presentation page,
1 - The module works perfectly on field_image not only with "images" media type but with "private images" too (see below "proposed resolution)
2- It doesn't work with "thumbnail" field even if formatter is set to "image". "Thumbnail" field is core hardcoded and it only appears in the display manager. Link this field to parent entity may be useful in case you display nodes with videos or remote videos and you wish to display a thumbnail in the teaser display nstead of the video_field. Video media types don't have 'image' field and the thumbnail field is supposed to display an image associated to the video.

Steps to reproduce

Proposed resolution

For usage with "private images", in src/InitialSettingsService.php set:

  /**
   * @var array of media sources
   */
  protected $mediasources = ['image', 'image_private', 'remote_video'];

As for video media types and thumbnails, perhaps there may be a settings as above for field types among with $formatters and $mediasources and . Something like

  /**
   * @var array of media sources
   */
  protected $mediafields = ['field_image', 'thumbnail'];

Remaining tasks

User interface changes

API changes

Data model changes

Feature request
Status

RTBC

Version

1.1

Component

Code

Created by

🇫🇷France erwangel

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

Comments & Activities

  • Issue created by @erwangel
  • 🇩🇪Germany stefan.korn Jossgrund

    @erwangel: Thanks for your review of the module and bringing up this interesting points.

    Currently the module is only targeting the source field of a media with image source type.

    The thumbnail is a base field of any media entity. Testing this a bit, it would work with thumbnail too if changing the code to allow for configuring thumbnail with link to parent entity checkbox and modifying the output to support this too.

    This would also allow to use it on remote video too.

    And thinking some more about this, I suppose it could work for any image field in any media entity.

    So if changing the approach I guess supporting any image field in any media entity would be the desired result. But this is quite a bigger rework of the code. I need to work a bit more on this.

    Another point:
    I am not sure what image_private media source is. This is not coming from core I suppose. Is it a module that is providing this or maybe a custom implementation on your end?
    But if the approach I described above would be feasible, maybe we can get rid of the media sources check all together.

  • Assigned to stefan.korn
  • Status changed to Needs work 7 months ago
  • 🇩🇪Germany stefan.korn Jossgrund
  • 🇩🇪Germany stefan.korn Jossgrund
    • stefan.korn committed 2a8088eb on 8.x-1.x
      Issue #3411452 by erwangel, stefan.korn: make it work with any image...
  • 🇩🇪Germany stefan.korn Jossgrund

    @erwangel: I committed solution to the dev branch which should do the following:

    - work with any image field on any media entity type, including thumbnail

    would be great if you can test this if you find the time.

  • Status changed to Needs review 7 months ago
  • 🇩🇪Germany stefan.korn Jossgrund
  • 🇫🇷France erwangel

    "Private images" appeared as an extra media type in my settings after the upgrade from Drupal 7 to 9. And I think one has to create this type if he wants to store images in a Private file system path (see settings @ /admin/config/media/file-system). The image field (field_media_image) of media image type doesn't permit to chose the storage on uploading; you have to define it in settings (see @ /admin/structure/media/manage/image/fields/media.image.field_media_image). So if for some of your images you want a private storage (outside of site root) you have to define a new media type (p.e. private_images) and set the appropriate storage. You can still access private images for display through styles but not directly by their url.

    I'll come back in a few days to test the new dev version. Thank you for making it.

  • 🇫🇷France erwangel

    The new dev looks fine. It works on all my media types. I had a look in your code and it seems the right approach. However it produces the default language links as pointed in issue 3316244 (url not translated) 🐛 Generated URL of parent entity is not translated Postponed: needs info . Have a look there; I commented it and proposed a working solution.

    Also I noticed that $formatters are defined in InitialSettingsService as ['image', 'responsive_image']. I tested and it's okay with both of them, but what about other formatters that modules may add (I have blazy and colorbox, but also image_field_tokens, I don't know where the last comes from perhaps token module). I understand we can't plan ahead what formatters may be available there. Perhaps make it clear in documentation and presentation page that the module acts only on core 'image' and 'responsive_image'.

    Blazy is widely used and it may be worth having some kind of compatibility. I tried to add 'blazy' in the $formatters array, the 'link to parent' option appeared in formatter's settings but it had no effect on display. I was not surprised as Blazy has it's own 'link to' called 'Media switcher' but it's mostly for switching to colorbox or other lightboxes supported by this module and anyhaw it lacks an option to 'link to the parent'.

    I think we can consider the $sources issue fixed and if you think a solution to make the module compatible with other formaters is possible, perhaps open an other issue.

  • Status changed to RTBC 7 months ago
  • 🇩🇪Germany stefan.korn Jossgrund
Production build 0.71.5 2024