public function ProviderRepository::getAll in Drupal 8
Same name in this branch
- 8 core/modules/media/src/OEmbed/ProviderRepository.php \Drupal\media\OEmbed\ProviderRepository::getAll()
- 8 core/modules/media/tests/modules/media_test_oembed/src/ProviderRepository.php \Drupal\media_test_oembed\ProviderRepository::getAll()
Same name and namespace in other branches
- 9 core/modules/media/src/OEmbed/ProviderRepository.php \Drupal\media\OEmbed\ProviderRepository::getAll()
Returns information on all available oEmbed providers.
Return value
\Drupal\media\OEmbed\Provider[] Returns an array of provider value objects, keyed by provider name.
Throws
\Drupal\media\OEmbed\ProviderException If the oEmbed provider information cannot be retrieved.
Overrides ProviderRepositoryInterface::getAll
2 calls to ProviderRepository::getAll()
- ProviderRepository::get in core/
modules/ media/ src/ OEmbed/ ProviderRepository.php - Returns information for a specific oEmbed provider.
- ProviderRepository::getAll in core/
modules/ media/ tests/ modules/ media_test_oembed/ src/ ProviderRepository.php - Returns information on all available oEmbed providers.
1 method overrides ProviderRepository::getAll()
- ProviderRepository::getAll in core/
modules/ media/ tests/ modules/ media_test_oembed/ src/ ProviderRepository.php - Returns information on all available oEmbed providers.
File
- core/
modules/ media/ src/ OEmbed/ ProviderRepository.php, line 73
Class
- ProviderRepository
- Retrieves and caches information about oEmbed providers.
Namespace
Drupal\media\OEmbedCode
public function getAll() {
$cache_id = 'media:oembed_providers';
$cached = $this
->cacheGet($cache_id);
if ($cached) {
return $cached->data;
}
try {
$response = $this->httpClient
->request('GET', $this->providersUrl);
} catch (RequestException $e) {
throw new ProviderException("Could not retrieve the oEmbed provider database from {$this->providersUrl}", NULL, $e);
}
$providers = Json::decode((string) $response
->getBody());
if (!is_array($providers) || empty($providers)) {
throw new ProviderException('Remote oEmbed providers database returned invalid or empty list.');
}
$keyed_providers = [];
foreach ($providers as $provider) {
try {
$name = (string) $provider['provider_name'];
$keyed_providers[$name] = new Provider($provider['provider_name'], $provider['provider_url'], $provider['endpoints']);
} catch (ProviderException $e) {
// Just skip all the invalid providers.
// @todo Log the exception message to help with debugging.
}
}
$this
->cacheSet($cache_id, $keyed_providers, $this->time
->getCurrentTime() + $this->maxAge);
return $keyed_providers;
}