public function UrlResolver::getProviderByUrl in Drupal 10
Same name and namespace in other branches
- 8 core/modules/media/src/OEmbed/UrlResolver.php \Drupal\media\OEmbed\UrlResolver::getProviderByUrl()
- 9 core/modules/media/src/OEmbed/UrlResolver.php \Drupal\media\OEmbed\UrlResolver::getProviderByUrl()
Tries to determine the oEmbed provider for a media asset URL.
Parameters
string $url: The media asset URL.
Return value
\Drupal\media\OEmbed\Provider The oEmbed provider for the asset.
Throws
\Drupal\media\OEmbed\ResourceException If the provider cannot be determined.
\Drupal\media\OEmbed\ProviderException If tne oEmbed provider causes an error.
Overrides UrlResolverInterface::getProviderByUrl
1 call to UrlResolver::getProviderByUrl()
- 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 126
Class
- UrlResolver
- Converts oEmbed media URLs into endpoint-specific resource URLs.
Namespace
Drupal\media\OEmbedCode
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);
if ($resource_url) {
return $this->resourceFetcher
->fetchResource($resource_url)
->getProvider();
}
throw new ResourceException('No matching provider found.', $url);
}