ProviderManager.php in Video Embed Field 8
File
src/ProviderManager.php
View source
<?php
namespace Drupal\video_embed_field;
use Drupal\Component\Plugin\Mapper\MapperInterface;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
class ProviderManager extends DefaultPluginManager implements ProviderManagerInterface, MapperInterface {
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
parent::__construct('Plugin/video_embed_field/Provider', $namespaces, $module_handler, 'Drupal\\video_embed_field\\ProviderPluginInterface', 'Drupal\\video_embed_field\\Annotation\\VideoEmbedProvider');
$this
->alterInfo('video_embed_field_provider_info');
}
public function getProvidersOptionList() {
$options = [];
foreach ($this
->getDefinitions() as $definition) {
$options[$definition['id']] = $definition['title'];
}
return $options;
}
public function loadDefinitionsFromOptionList($options) {
$definitions = [];
if (count(array_keys($options, '0')) == count($options) || empty($options)) {
return $this
->getDefinitions();
}
else {
foreach ($options as $provider_id => $enabled) {
if ($enabled) {
$definitions[$provider_id] = $this
->getDefinition($provider_id);
}
}
}
return $definitions;
}
public function filterApplicableDefinitions(array $definitions, $user_input) {
foreach ($definitions as $definition) {
$is_applicable = $definition['class']::isApplicable($user_input);
if ($is_applicable) {
return $definition;
}
}
return FALSE;
}
public function loadProviderFromInput($input) {
$definition = $this
->loadDefinitionFromInput($input);
return $definition ? $this
->createInstance($definition['id'], [
'input' => $input,
]) : FALSE;
}
public function loadDefinitionFromInput($input) {
return $this
->filterApplicableDefinitions($this
->getDefinitions(), $input);
}
}