function UrlResolver::getResourceUrl

Same name in this branch
  1. 9 core/modules/media/tests/modules/media_test_oembed/src/UrlResolver.php \Drupal\media_test_oembed\UrlResolver::getResourceUrl()
Same name in other branches
  1. 8.9.x core/modules/media/src/OEmbed/UrlResolver.php \Drupal\media\OEmbed\UrlResolver::getResourceUrl()
  2. 8.9.x core/modules/media/tests/modules/media_test_oembed/src/UrlResolver.php \Drupal\media_test_oembed\UrlResolver::getResourceUrl()
  3. 10 core/modules/media/src/OEmbed/UrlResolver.php \Drupal\media\OEmbed\UrlResolver::getResourceUrl()
  4. 10 core/modules/media/tests/modules/media_test_oembed/src/UrlResolver.php \Drupal\media_test_oembed\UrlResolver::getResourceUrl()
  5. 11.x core/modules/media/src/OEmbed/UrlResolver.php \Drupal\media\OEmbed\UrlResolver::getResourceUrl()
  6. 11.x core/modules/media/tests/modules/media_test_oembed/src/UrlResolver.php \Drupal\media_test_oembed\UrlResolver::getResourceUrl()

Overrides UrlResolverInterface::getResourceUrl

1 call to UrlResolver::getResourceUrl()
UrlResolver::getResourceUrl in core/modules/media/tests/modules/media_test_oembed/src/UrlResolver.php
Builds the resource URL for a media asset URL.
1 method overrides UrlResolver::getResourceUrl()
UrlResolver::getResourceUrl in core/modules/media/tests/modules/media_test_oembed/src/UrlResolver.php
Builds the resource URL for a media asset URL.

File

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

Class

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

Namespace

Drupal\media\OEmbed

Code

public function getResourceUrl($url, $max_width = NULL, $max_height = NULL) {
    // Try to get the resource URL from the static cache.
    if (isset($this->urlCache[$url])) {
        return $this->urlCache[$url];
    }
    // Try to get the resource URL from the persistent cache.
    $cache_id = "media:oembed_resource_url:{$url}:{$max_width}:{$max_height}";
    $cached = $this->cacheBackend
        ->get($cache_id);
    if ($cached) {
        $this->urlCache[$url] = $cached->data;
        return $this->urlCache[$url];
    }
    $provider = $this->getProviderByUrl($url);
    $resource_url = $this->getEndpointMatchingUrl($url, $provider);
    $parsed_url = UrlHelper::parse($resource_url);
    if ($max_width) {
        $parsed_url['query']['maxwidth'] = $max_width;
    }
    if ($max_height) {
        $parsed_url['query']['maxheight'] = $max_height;
    }
    // Let other modules alter the resource URL, because some oEmbed providers
    // provide extra parameters in the query string. For example, Instagram also
    // supports the 'omitscript' parameter.
    $this->moduleHandler
        ->alter('oembed_resource_url', $parsed_url, $provider);
    $resource_url = $parsed_url['path'] . '?' . rawurldecode(UrlHelper::buildQuery($parsed_url['query']));
    $this->urlCache[$url] = $resource_url;
    $this->cacheBackend
        ->set($cache_id, $resource_url);
    return $resource_url;
}

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