Skip to content
Snippets Groups Projects
Unverified Commit a0a28bdd authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3438618 by larowlan, longwave, alexpott, martijn de wit, askibinski,...

Issue #3438618 by larowlan, longwave, alexpott, martijn de wit, askibinski, seanb: Allow opting out of oembed discovery
parent eab46c49
No related branches found
No related tags found
13 merge requests!11197Issue #3506427 by eduardo morales alberti: Remove responsive_image.ajax from hook,!11131[10.4.x-only-DO-NOT-MERGE]: Issue ##2842525 Ajax attached to Views exposed filter form does not trigger callbacks,!10786Issue #3490579 by shalini_jha, mstrelan: Add void return to all views...,!5423Draft: Resolve #3329907 "Test2",!3878Removed unused condition head title for views,!3818Issue #2140179: $entity->original gets stale between updates,!3478Issue #3337882: Deleted menus are not removed from content type config,!3154Fixes #2987987 - CSRF token validation broken on routes with optional parameters.,!2964Issue #2865710 : Dependencies from only one instance of a widget are used in display modes,!2062Issue #3246454: Add weekly granularity to views date sort,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!617Issue #3043725: Provide a Entity Handler for user cancelation,!579Issue #2230909: Simple decimals fail to pass validation
Pipeline #357364 passed with warnings
Pipeline: drupal

#357366

    ......@@ -2,3 +2,4 @@ icon_base_uri: 'public://media-icons/generic'
    iframe_domain: ~
    oembed_providers_url: 'https://oembed.com/providers.json'
    standalone_url: false
    oembed_discovery: false
    ......@@ -15,6 +15,9 @@ media.settings:
    standalone_url:
    type: boolean
    label: 'Allow media items to be viewed standalone at /media/{id}'
    oembed_discovery:
    type: boolean
    label: 'Allow oEmbed discovery'
    media.type.*:
    type: config_entity
    ......
    ......@@ -27,3 +27,10 @@ function media_removed_post_updates(): array {
    function media_post_update_media_author_views_filter_update(): void {
    // Empty update function to clear the Views data cache.
    }
    /**
    * Set the oembed_discovery setting.
    */
    function media_post_update_set_oembed_discovery(): void {
    \Drupal::configFactory()->getEditable('media.settings')->set('oembed_discovery', TRUE)->save(TRUE);
    }
    ......@@ -9,7 +9,7 @@ services:
    parent: default_plugin_manager
    media.oembed.url_resolver:
    class: Drupal\media\OEmbed\UrlResolver
    arguments: ['@media.oembed.provider_repository', '@media.oembed.resource_fetcher', '@http_client', '@module_handler', '@cache.default']
    arguments: ['@media.oembed.provider_repository', '@media.oembed.resource_fetcher', '@http_client', '@module_handler', '@cache.default', '@config.factory']
    Drupal\media\OEmbed\UrlResolverInterface: '@media.oembed.url_resolver'
    media.oembed.provider_repository:
    class: Drupal\media\OEmbed\ProviderRepository
    ......
    ......@@ -5,6 +5,7 @@
    use Drupal\Component\Utility\Html;
    use Drupal\Component\Utility\UrlHelper;
    use Drupal\Core\Cache\CacheBackendInterface;
    use Drupal\Core\Config\ConfigFactoryInterface;
    use Drupal\Core\Extension\ModuleHandlerInterface;
    use GuzzleHttp\ClientInterface;
    use Psr\Http\Client\ClientExceptionInterface;
    ......@@ -63,24 +64,24 @@ class UrlResolver implements UrlResolverInterface {
    /**
    * Constructs a UrlResolver object.
    *
    * @param \Drupal\media\OEmbed\ProviderRepositoryInterface $providers
    * The oEmbed provider repository service.
    * @param \Drupal\media\OEmbed\ResourceFetcherInterface $resource_fetcher
    * The OEmbed resource fetcher service.
    * @param \GuzzleHttp\ClientInterface $http_client
    * The HTTP client.
    * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
    * The module handler service.
    * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
    * The cache backend.
    */
    public function __construct(ProviderRepositoryInterface $providers, ResourceFetcherInterface $resource_fetcher, ClientInterface $http_client, ModuleHandlerInterface $module_handler, CacheBackendInterface $cache_backend) {
    public function __construct(
    ProviderRepositoryInterface $providers,
    ResourceFetcherInterface $resource_fetcher,
    ClientInterface $http_client,
    ModuleHandlerInterface $module_handler,
    CacheBackendInterface $cache_backend,
    protected ?ConfigFactoryInterface $configFactory = NULL,
    ) {
    $this->providers = $providers;
    $this->resourceFetcher = $resource_fetcher;
    $this->httpClient = $http_client;
    $this->moduleHandler = $module_handler;
    $this->cacheBackend = $cache_backend;
    if ($configFactory === NULL) {
    $this->configFactory = \Drupal::configFactory();
    @trigger_error('Calling ' . __METHOD__ . ' without the $configFactory argument is deprecated in drupal:11.1.0 and will be required in drupal:12.0.0. See https://www.drupal.org/node/3481570', E_USER_DEPRECATED);
    }
    }
    /**
    ......@@ -136,9 +137,12 @@ public function getProviderByUrl($url) {
    }
    }
    $resource_url = $this->discoverResourceUrl($url);
    if ($resource_url) {
    return $this->resourceFetcher->fetchResource($resource_url)->getProvider();
    if ($this->configFactory->get('media.settings')->get('oembed_discovery')) {
    $resource_url = $this->discoverResourceUrl($url);
    if ($resource_url) {
    return $this->resourceFetcher->fetchResource($resource_url)
    ->getProvider();
    }
    }
    throw new ResourceException('No matching provider found.', $url);
    ......
    This diff is collapsed.
    <?php
    declare(strict_types=1);
    namespace Drupal\Tests\media\Functional\Update;
    use Drupal\FunctionalTests\Update\UpdatePathTestBase;
    /**
    * @covers \media_post_update_set_oembed_discovery
    * @group media
    */
    class MediaSettingsUpdateTest extends UpdatePathTestBase {
    /**
    * {@inheritdoc}
    */
    protected function setDatabaseDumpFiles(): void {
    $this->databaseDumpFiles = [
    __DIR__ . '/../../../fixtures/update/11.0-x-minimal-media.php.gz',
    ];
    }
    /**
    * Tests update path for media oembed discovery setting.
    */
    public function testRunUpdates(): void {
    self::assertNull(\Drupal::config('media.settings')->get('oembed_discovery'));
    $this->runUpdates();
    self::assertTrue(\Drupal::config('media.settings')->get('oembed_discovery'));
    }
    }
    ......@@ -4,6 +4,7 @@
    namespace Drupal\Tests\media\Functional;
    use Drupal\media\OEmbed\ResourceException;
    use Drupal\Tests\media\Traits\OEmbedTestTrait;
    // cspell:ignore dailymotion
    ......@@ -115,6 +116,11 @@ public static function providerUrlDiscovery() {
    'video_dailymotion.html',
    'https://www.dailymotion.com/services/oembed?url=video_dailymotion.html',
    ],
    'Discovery disabled' => [
    'video_dailymotion.html',
    'https://www.dailymotion.com/services/oembed?url=video_dailymotion.html',
    FALSE,
    ],
    ];
    }
    ......@@ -125,6 +131,8 @@ public static function providerUrlDiscovery() {
    * The asset URL to resolve.
    * @param string $resource_url
    * The expected oEmbed resource URL of the asset.
    * @param bool $discovery_enabled
    * Whether to enable oEmbed resource discovery.
    *
    * @covers ::discoverResourceUrl
    * @covers ::getProviderByUrl
    ......@@ -132,7 +140,11 @@ public static function providerUrlDiscovery() {
    *
    * @dataProvider providerUrlDiscovery
    */
    public function testUrlDiscovery($url, $resource_url): void {
    public function testUrlDiscovery($url, $resource_url, bool $discovery_enabled = TRUE): void {
    \Drupal::configFactory()->getEditable('media.settings')->set('oembed_discovery', $discovery_enabled)->save();
    if (!$discovery_enabled) {
    $this->expectException(ResourceException::class);
    }
    $this->assertSame(
    $this->container->get('media.oembed.url_resolver')->getResourceUrl($url),
    $resource_url
    ......
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please register or to comment