5 * Contains \Drupal\video\ProviderManager.
8 namespace Drupal\video;
10 use Drupal\Component\Plugin\Mapper\MapperInterface;
11 use Drupal\Core\Cache\CacheBackendInterface;
12 use Drupal\Core\Extension\ModuleHandlerInterface;
13 use Drupal\Core\Plugin\DefaultPluginManager;
16 * Gathers the provider plugins.
18 class ProviderManager extends DefaultPluginManager implements ProviderManagerInterface, MapperInterface {
23 public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
24 parent::__construct('Plugin/video/Provider', $namespaces, $module_handler, 'Drupal\video\ProviderPluginInterface', 'Drupal\video\Annotation\VideoEmbeddableProvider');
30 public function getProvidersOptionList() {
32 foreach ($this->getDefinitions() as $definition) {
33 $options[$definition['id']] = $definition['label'];
41 public function loadDefinitionsFromOptionList($options) {
43 // When no options are selected, all plugins are applicable.
44 if (count(array_keys($options, '0')) == count($options) || empty($options)) {
45 return $this->getDefinitions();
48 foreach ($options as $provider_id => $enabled) {
50 $definitions[$provider_id] = $this->getDefinition($provider_id);
60 public function loadApplicableDefinitionMatches(array $definitions, $user_input) {
61 foreach ($definitions as $definition) {
62 foreach($definition['regular_expressions'] as $reqular_expr){
63 if (preg_match($reqular_expr, $user_input, $matches)) {
64 return array('definition' => $definition, 'matches' => $matches);
74 public function loadProviderFromStream($stream, $file, $metadata = array(), $settings = array()) {
75 $definitions = $this->getDefinitions();
76 foreach ($definitions as $definition) {
77 if($definition['stream_wrapper'] == $stream){
78 return $definition ? $this->createInstance($definition['id'], ['file' => $file, 'metadata' => $metadata, 'settings' => $settings]) : FALSE;