Allow modules to alter the name of the field used for image-specific functionality

Created on 7 June 2023, over 1 year ago

Problem/Motivation

The MediaImageDecorator adds image-specific functionality to Entity Embed when the current media entity is image-sourced. This functionality includes accepting alt text and title inputs. To determine whether a media entity should be treated as image-esque media, getMediaImageSourceField gets the media's source field and checks to see if it is an image field. This is perfectly reasonable.
However, I have a scenario where this logic excludes entities that can support (and need) image-specific treatment. I maintain the Brandfolder β†’ module and we're about to offer Entity Browser and Entity Embed support there. That module provides a media source plugin for images stored in Brandfolder, which is an external DAM. Entities using that source have a "source field" that is not an image field (it's a text field containing a unique ID mapping to the external system), but they do have a fully functional Drupal image field that is derived from that source and is kept in sync with it.

Steps to reproduce

  • Install and configure Entity Embed + Dependencies
  • Install and configure Brandfolder module
  • Create a media type with the "Brandfolder Image" source
  • Allow that media type to be selected with the relevant entity browsers & entity embed buttons
  • Embed a Brandfolder image media entity via Entity Embed
  • Observe that alt text field is not presented in the embed dialog

Proposed resolution

Allow modules to alter the field name returned by MediaImageDecorator::getMediaImageSourceField().

Remaining tasks

Review.

User interface changes

Image-related fields would appear to end users if they are using a module that takes advantage of this new customizability.

API changes

New hook_entity_embed_media_image_source_field_alter hook. There should be no BC issues.
New ModuleHandlerInterface argument in MediaImageDecorator constructor, to enable its method to invoke that hook. If this class is only used internally, there should be no BC issues.

Data model changes

None.

✨ Feature request
Status

Needs review

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States ndewhurst USA

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

Comments & Activities

Production build 0.71.5 2024