Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / media / tests / modules / media_test_oembed / src / UrlResolver.php
1 <?php
2
3 namespace Drupal\media_test_oembed;
4
5 use Drupal\media\OEmbed\UrlResolver as BaseUrlResolver;
6
7 /**
8  * Overrides the oEmbed URL resolver service for testing purposes.
9  */
10 class UrlResolver extends BaseUrlResolver {
11
12   /**
13    * Sets the endpoint URL for an oEmbed resource URL.
14    *
15    * @param string $url
16    *   The resource URL.
17    * @param string $endpoint_url
18    *   The endpoint URL.
19    */
20   public static function setEndpointUrl($url, $endpoint_url) {
21     $urls = \Drupal::state()->get(static::class, []);
22     $urls[$url] = $endpoint_url;
23     \Drupal::state()->set(static::class, $urls);
24   }
25
26   /**
27    * {@inheritdoc}
28    */
29   public function getResourceUrl($url, $max_width = NULL, $max_height = NULL) {
30     $urls = \Drupal::state()->get(static::class, []);
31
32     if (isset($urls[$url])) {
33       return $urls[$url];
34     }
35     return parent::getResourceUrl($url, $max_width, $max_height);
36   }
37
38 }