Overview

#3530351: Decouple image+video (URI) shape matching from specific image+video file types/extensions is about avoiding assumptions in the shape definition about specific image file types.

This is about avoiding assumptions in XB's shape matching that require/assume the Standard install profile's image media type.


#3462709: Introduce `hook_storable_prop_shape_alter()`, use it to prefer the Media Library widget for "image" PropShape if Media Library is installed introduced in August 2024:

function media_library_storage_prop_shape_alter(CandidateStorablePropShape $storable_prop_shape): void {
  if ($storable_prop_shape->shape->schema == ['type' => 'object', '$ref' => 'json-schema-definitions://experience_builder.module/image']) {
    // @todo Allow configuring which media type, for now this assumes the
    //   Standard 'image' media type.
    // @see core/profiles/standard/config/optional/media.type.image.yml
    if (!MediaType::load('image')) {
      return;
    }
…

And this still lives on to this day. But what about sites without the image MediaType? Or sites with multiple image media types?

Proposed resolution

All MediaTypes that use the Image MediaSource plugin (\Drupal\media\Plugin\media\Source\Image) should be supported.

User interface changes

Multiple (all!) image-sourced media types should be selectable when using the Media Library Widget for populating a $ref: json-schema-definitions://experience_builder.module/image.

CommentFileSizeAuthor
#6 multiple image media types.gif1.3 MBwim leers
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

wim leers created an issue. See original summary.

wim leers’s picture

The initial hard technical blocker:

new FieldPropExpression(EntityDataDefinition::create('media', 'image'), …)

needs to be able to be

new FieldPropExpression(EntityDataDefinition::create('media', ['image', 'wild_life_photos']), …)

… but
\Drupal\Core\Entity\TypedData\EntityDataDefinition::create() does not allow that:

public static function create($entity_type_id = NULL, $bundle = NULL) {

Investigation led to discovering an upstream core issue for this: #2169813: Support deriving fields from entity definitions with multiple bundles (or zero bundles). Which … I happen to have contributed to 8 years ago for JSON:API. 😅👴

wim leers credited bnjmnm.

wim leers’s picture

Tests are passing, and are proving that it is now possible to target different fields (i.e. bundle-specific fields) of the same field type across multiple bundles of the same entity type.

This effectively makes this behave similarly to how #3487079: Pages have images usable for SEO purposes handled the picking of the the image to use in Metatags. (And this will automatically start happening on existing sites with this change.)

And … it actually works thanks to @bnjmnm's work on the Media Library Widget:

Future work

Note: the "same field type" requirement I referred to is simply because the props being targeted in each FieldPropExpression cannot (yet) vary by bundle; only the field name can. This could be expanded in a follow-up issue, which would allow for e.g. different media sources that all provide similar media: the Image MediaSource (powered by an image/file field type for local images), but a "remote image" MediaType — for example powered by core's OEmbed MediaSource, using the (disabled by default) Flickr oEmbed provider.

Created #3530533: Support image shape matching against multiple bundles of multiple MediaSources (`image` + `oembed` + `acquia_dam_asset` + …) for that.

wim leers’s picture

Title: Decouple image shape matching from the `image` MediaType » Decouple image shape matching from the `image` MediaType: support matching multiple bundles of a single MediaSources (`image`)
wim leers’s picture

Status: Needs review » Reviewed & tested by the community

Tests are green! Follow-up for next steps exists.

Self-RTBC'ing and merging because nobody else knows the Shape matching area well enough to review it.

  • wim leers committed cb4c5a3d on 0.x
    Issue #3530521 by wim leers, bnjmnm: Decouple image shape matching from...
wim leers’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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