3 namespace Drupal\video_embed_field;
5 use Drupal\Component\Plugin\Mapper\MapperInterface;
6 use Drupal\Core\Cache\CacheBackendInterface;
7 use Drupal\Core\Extension\ModuleHandlerInterface;
8 use Drupal\Core\Plugin\DefaultPluginManager;
11 * Gathers the provider plugins.
13 class ProviderManager extends DefaultPluginManager implements ProviderManagerInterface, MapperInterface {
18 public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
19 parent::__construct('Plugin/video_embed_field/Provider', $namespaces, $module_handler, 'Drupal\video_embed_field\ProviderPluginInterface', 'Drupal\video_embed_field\Annotation\VideoEmbedProvider');
20 $this->alterInfo('video_embed_field_provider_info');
26 public function getProvidersOptionList() {
28 foreach ($this->getDefinitions() as $definition) {
29 $options[$definition['id']] = $definition['title'];
37 public function loadDefinitionsFromOptionList($options) {
39 // When no options are selected, all plugins are applicable.
40 if (count(array_keys($options, '0')) == count($options) || empty($options)) {
41 return $this->getDefinitions();
44 foreach ($options as $provider_id => $enabled) {
46 $definitions[$provider_id] = $this->getDefinition($provider_id);
56 public function filterApplicableDefinitions(array $definitions, $user_input) {
57 foreach ($definitions as $definition) {
58 $is_applicable = $definition['class']::isApplicable($user_input);
69 public function loadProviderFromInput($input) {
70 $definition = $this->loadDefinitionFromInput($input);
71 return $definition ? $this->createInstance($definition['id'], ['input' => $input]) : FALSE;
77 public function loadDefinitionFromInput($input) {
78 return $this->filterApplicableDefinitions($this->getDefinitions(), $input);