ProviderRepository.php

Same filename in this branch
  1. 9 core/modules/media/src/OEmbed/ProviderRepository.php
Same filename in other branches
  1. 8.9.x core/modules/media/src/OEmbed/ProviderRepository.php
  2. 8.9.x core/modules/media/tests/modules/media_test_oembed/src/ProviderRepository.php
  3. 10 core/modules/media/src/OEmbed/ProviderRepository.php
  4. 10 core/modules/media/tests/modules/media_test_oembed/src/ProviderRepository.php
  5. 11.x core/modules/media/src/OEmbed/ProviderRepository.php
  6. 11.x core/modules/media/tests/modules/media_test_oembed/src/ProviderRepository.php

Namespace

Drupal\media_test_oembed

File

core/modules/media/tests/modules/media_test_oembed/src/ProviderRepository.php

View source
<?php

namespace Drupal\media_test_oembed;

use Drupal\media\OEmbed\Provider;
use Drupal\media\OEmbed\ProviderRepository as BaseProviderRepository;

/**
 * Overrides the oEmbed provider repository service for testing purposes.
 *
 * This service does not use caching at all, and will always try to retrieve
 * provider data from state before calling the parent methods.
 */
class ProviderRepository extends BaseProviderRepository {
    
    /**
     * {@inheritdoc}
     */
    public function getAll() {
        return \Drupal::state()->get(static::class) ?: parent::getAll();
    }
    
    /**
     * {@inheritdoc}
     */
    public function get($provider_name) {
        $providers = \Drupal::state()->get(static::class, []);
        if (isset($providers[$provider_name])) {
            return $providers[$provider_name];
        }
        return parent::get($provider_name);
    }
    
    /**
     * Stores an oEmbed provider value object in state.
     *
     * @param \Drupal\media\OEmbed\Provider $provider
     *   The provider to store.
     */
    public function setProvider(Provider $provider) {
        $providers = \Drupal::state()->get(static::class, []);
        $name = $provider->getName();
        $providers[$name] = $provider;
        \Drupal::state()->set(static::class, $providers);
    }

}

Classes

Title Deprecated Summary
ProviderRepository Overrides the oEmbed provider repository service for testing purposes.

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