Problem/Motivation

Quoting @seanb from Jan 7, 2018:

Discussed the link dependency with chr.fritsch in slack. We agreed link fields are best suited to store the links to oEmbed media. String fields are currently also allowed as a source field and we should probably remove that. Any thoughts?

#2831944-66: Implement media source plugin for remote video via oEmbed

The link or uri field types would be more suitable.

Then, in #2831944-67: Implement media source plugin for remote video via oEmbed, @chr.fritsch removed string and kept only link.

Finally, in #2831944-77 through -83, @alexpott, @chr.fritsch, @phenaproxima, @dawehner and @samuel.mortenson went back and forth what the best approach is. Considerations were:

  • limiting dependencies (not requiring the Link module)
  • predictability (same field type used on all sites)
  • no impact on UX anyway (since the media source field would not be populated using the default widget for the media source field's field type anyway, and for presenting, the oEmbed formatter would be used anyway — which notably and AFAICT unintentionally still supports the link field type! 😅)

… and hence string was chosen.
(I'm not sure why \Drupal\Core\Field\Plugin\Field\FieldType\UriItem was not considered? 🤔🤷)

But, this did not consider one aspect that was perhaps irrelevant, but is relevant now: metadata/Typed Data!

The consequence is that it is impossible to fetch the oEmbed URL or oEmbed XML/JSON blob for any oEmbed Media entities. All you can get is the URL originally entered by the content author (e.g. https://giphy.com/gifs/service-department-customer-T8Dhl1KPyzRqU) and it is impossible to retrieve the corresponding resource to actually display to visitors (e.g. https://media3.giphy.com/media/T8Dhl1KPyzRqU/giphy.gif).

⚠️ This makes it impossible for https://drupal.org/project/canvas to pass the structured data of oEmbed media items to components.

Steps to reproduce

N/A

Proposed resolution

Use a new field type that provides access to relevant oEmbed information via Typed Data properties.

Rough proposal:

introduce OEmbedUriItem extends \Drupal\Core\Field\Plugin\Field\FieldType\UriItem, with:

  1. the existing value property being what the user would've entered
  2. a computed type property to be one of \Drupal\media\OEmbed\Resource::TYPE_*
  3. a computed resource property to pass along the results for \Drupal\media\OEmbed\ResourceFetcher::createResource()
  4. a computed url property to pass along the results for \Drupal\media\OEmbed\UrlResolver::getResourceUrl()

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3567249

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

Citing from #3550750's https://git.drupalcode.org/project/canvas/-/merge_requests/400:

      // Test an expression for a reference field that branches based on the referenced
      // entity type and bundle:
      // 1. in one case, it fetches a reference of a reference (local image)
      // 2. in another case, it fetches a computed property (remote image)
      // ⚠️🚨 Drupal core's oEmbed MediaSource plugin does not play nice with
      // Typed Data! It uses the `string` field type to store a string with
      // no additional semantic information, whereas it's really storing the oEmbed URL
      // entered by the content author. It then uses a field formatter to
      // fetch the actual image URL from oEmbed provider.
      // For example, this is entered (and stored!):
      // @code
      // https://giphy.com/gifs/service-department-customer-T8Dhl1KPyzRqU
      // @endcode
      // And the field formatter fetches the oEmbed information to determine the
      // image URL to load is:
      // @code
      // https://media3.giphy.com/media/T8Dhl1KPyzRqU/giphy.gif
      // @endcode
      // @see https://www.drupal.org/project/media_remote_image
      // @todo Create core issue to change the field type used by the oEmbed MediaSource plugin

This is that issue.

quietone’s picture

Version: 11.3.x-dev » main

joaopauloc.dev made their first commit to this issue’s fork.