function UrlResolver::getEndpointMatchingUrl

Same name in other branches
  1. 10 core/modules/media/src/OEmbed/UrlResolver.php \Drupal\media\OEmbed\UrlResolver::getEndpointMatchingUrl()
  2. 11.x core/modules/media/src/OEmbed/UrlResolver.php \Drupal\media\OEmbed\UrlResolver::getEndpointMatchingUrl()

For the given media item URL find an endpoint with schemes that match.

Parameters

string $url: The media URL used to lookup the matching endpoint.

\Drupal\media\OEmbed\Provider $provider: The oEmbed provider for the asset.

Return value

string The resource url.

1 call to UrlResolver::getEndpointMatchingUrl()
UrlResolver::getResourceUrl in core/modules/media/src/OEmbed/UrlResolver.php
Builds the resource URL for a media asset URL.

File

core/modules/media/src/OEmbed/UrlResolver.php, line 200

Class

UrlResolver
Converts oEmbed media URLs into endpoint-specific resource URLs.

Namespace

Drupal\media\OEmbed

Code

protected function getEndpointMatchingUrl($url, Provider $provider) {
    $endpoints = $provider->getEndpoints();
    $resource_url = reset($endpoints)->buildResourceUrl($url);
    foreach ($endpoints as $endpoint) {
        if ($endpoint->matchUrl($url)) {
            $resource_url = $endpoint->buildResourceUrl($url);
            break;
        }
    }
    return $resource_url ?? reset($endpoints)->buildResourceUrl($url);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.