Issue #3008712 by phjou, s.abbott, msuthars, Sam152, chr.fritsch, phenaproxima: oEmbed URL resolution does not take multiple endpoints into account
parent
10b44563c3
commit
600da9f81b
|
@ -158,10 +158,8 @@ class UrlResolver implements UrlResolverInterface {
|
|||
}
|
||||
|
||||
$provider = $this->getProviderByUrl($url);
|
||||
$endpoints = $provider->getEndpoints();
|
||||
$endpoint = reset($endpoints);
|
||||
$resource_url = $endpoint->buildResourceUrl($url);
|
||||
|
||||
$resource_url = $this->getEndpointMatchingUrl($url, $provider);
|
||||
$parsed_url = UrlHelper::parse($resource_url);
|
||||
if ($max_width) {
|
||||
$parsed_url['query']['maxwidth'] = $max_width;
|
||||
|
@ -181,4 +179,27 @@ class UrlResolver implements UrlResolverInterface {
|
|||
return $resource_url;
|
||||
}
|
||||
|
||||
/**
|
||||
* For the given media item URL find an endpoint with schemes that match.
|
||||
*
|
||||
* @param string $url
|
||||
* The media URL used to lookup the matching endpoint.
|
||||
* @param \Drupal\media\OEmbed\Provider $provider
|
||||
* The oEmbed provider for the asset.
|
||||
*
|
||||
* @return string
|
||||
* The resource url.
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -72,5 +72,35 @@
|
|||
"discovery": true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"provider_name": "Facebook",
|
||||
"provider_url": "https:\/\/www.facebook.com\/",
|
||||
"endpoints": [
|
||||
{
|
||||
"schemes": [
|
||||
"https:\/\/www.facebook.com\/*\/posts\/*",
|
||||
"https:\/\/www.facebook.com\/photos\/*",
|
||||
"https:\/\/www.facebook.com\/*\/photos\/*",
|
||||
"https:\/\/www.facebook.com\/photo.php*",
|
||||
"https:\/\/www.facebook.com\/photo.php",
|
||||
"https:\/\/www.facebook.com\/*\/activity\/*",
|
||||
"https:\/\/www.facebook.com\/permalink.php",
|
||||
"https:\/\/www.facebook.com\/media\/set?set=*",
|
||||
"https:\/\/www.facebook.com\/questions\/*",
|
||||
"https:\/\/www.facebook.com\/notes\/*\/*\/*"
|
||||
],
|
||||
"url": "https:\/\/www.facebook.com\/plugins\/post\/oembed.json",
|
||||
"discovery": true
|
||||
},
|
||||
{
|
||||
"schemes": [
|
||||
"https:\/\/www.facebook.com\/*\/videos\/*",
|
||||
"https:\/\/www.facebook.com\/video.php"
|
||||
],
|
||||
"url": "https:\/\/www.facebook.com\/plugins\/video\/oembed.json",
|
||||
"discovery": true
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
|
|
@ -50,6 +50,10 @@ class UrlResolverTest extends MediaFunctionalTestBase {
|
|||
'http://www.collegehumor.com/video/40002870/lets-not-get-a-drink-sometime',
|
||||
'http://www.collegehumor.com/oembed.json?url=http://www.collegehumor.com/video/40002870/lets-not-get-a-drink-sometime',
|
||||
],
|
||||
'match by endpoint: Facebook' => [
|
||||
'https://www.facebook.com/facebook/videos/10153231379946729/',
|
||||
'https://www.facebook.com/plugins/video/oembed.json?url=https://www.facebook.com/facebook/videos/10153231379946729/',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue