Problem/Motivation

Oembed supports two mechanisms of discovery as follows:

Drupal intends to support both however URL discovery does not work without a matching provider entry.

There is analysis and ideas in the duplicate issue, #3267260: Are we implementing oEmbed discovery correctly/efficiently?, that should be read as well.

Steps to reproduce

On a website add a link attribute to the page header per the discovery spec (link above)
Add a json endpoint to serve the oembed data
Note Drupal fetches the JSON from the endpoint
But then after fetching that it refers back to the providers list to find a matching endpoint
Finding none, it deems the oembed URL invalid.

The code in UrlResolver (lines 165-167) looks like this

$provider = $this->getProviderByUrl($url); // 👈️ This does URL discovery to determine the provider

$resource_url = $this->getEndpointMatchingUrl($url, $provider); // 👈️ But this reverts back to checking provider endpoints.

In getProviderByUrl we already have the $resource_url if we did URL discovery. But rather than use this, we use it to find the provider only

/**
   * {@inheritdoc}
   */
  public function getProviderByUrl($url) {
    // Check the URL against every scheme of every endpoint of every provider
    // until we find a match.
    foreach ($this->providers->getAll() as $provider_info) {
      foreach ($provider_info->getEndpoints() as $endpoint) {
        if ($endpoint->matchUrl($url)) {
          return $provider_info;
        }
      }
    }

    $resource_url = $this->discoverResourceUrl($url); // 👈️ We have the resource URL here
    if ($resource_url) {
      return $this->resourceFetcher->fetchResource($resource_url)->getProvider(); // 👈️ But we instead return just the provider
    }

    throw new ResourceException('No matching provider found.', $url);
  }

And then we return to getResourceUrl and the next call is

    $resource_url = $this->getEndpointMatchingUrl($url, $provider);

but we already had the $resource_url from discovery - we just discarded it to find the provider.

And then in ::getEndpointMatchingUrl we consult the endpoints in the provider to get the resource url. Which without a valid provider returns nothing

Isn't the point of URL discovery to allow oEmbed without needing to be listed in providers.json etc?

Proposed resolution

We have #3438618: Allow opting out of oEmbed discovery to make url discovery an extra feature. But it doesn't really work anyway - so should we just punt it to contrib?

Remaining tasks

Decide course of action

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3589392

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

larowlan created an issue. See original summary.

larowlan’s picture

quietone’s picture

Work done by longwave using an LLM that identified this as a duplicate of #3267260: Are we implementing oEmbed discovery correctly/efficiently? and suggested closing this one. While there is valuable discussion over in that issue this one have a more succinct issue summary, which makes it easier for contributors to grasp the situation. So, I am closing the other issue and adding a recommendation to the issue summary that that issue is read and becomes part of the discussion here. At least, then, we have only 1 issue where this problem is discusses.

bela shaheen made their first commit to this issue’s fork.

bela shaheen changed the visibility of the branch 3589392-media-oembed-url to hidden.

bela shaheen changed the visibility of the branch oembed-url-discovery to hidden.

bela shaheen changed the visibility of the branch 3589392-oembed-url-discovery3589392- to hidden.