diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index cc450d35..480d6e45 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -25,6 +25,14 @@ public function getConfigTreeBuilder() $rootNode ->children() ->scalarNode('soundcloud_api_key')->defaultValue('YOUR_CLIENT_ID')->end() + ->arrayNode('remote_video') + ->addDefaultsIfNotSet() + ->children() + ->booleanNode('vimeo')->defaultTrue()->end() + ->booleanNode('youtube')->defaultTrue()->end() + ->booleanNode('dailymotion')->defaultTrue()->end() + ->end() + ->end() ->end(); diff --git a/DependencyInjection/KunstmaanMediaExtension.php b/DependencyInjection/KunstmaanMediaExtension.php index 5d994501..02461692 100644 --- a/DependencyInjection/KunstmaanMediaExtension.php +++ b/DependencyInjection/KunstmaanMediaExtension.php @@ -39,6 +39,7 @@ public function load(array $configs, ContainerBuilder $container) ) ); $container->setParameter('kunstmaan_media.soundcloud_api_key', $config['soundcloud_api_key']); + $container->setParameter('kunstmaan_media.remote_video', $config['remote_video']); $loader->load('services.yml'); $loader->load('handlers.yml'); diff --git a/Form/RemoteVideo/RemoteVideoType.php b/Form/RemoteVideo/RemoteVideoType.php index 977b03a0..42dbd926 100644 --- a/Form/RemoteVideo/RemoteVideoType.php +++ b/Form/RemoteVideo/RemoteVideoType.php @@ -17,6 +17,20 @@ class RemoteVideoType extends AbstractType { + /** + * @var array + */ + protected $configuration = array(); + + /** + * Constructor, gets the RemoteVideo configuration + * @param array $configuration + */ + public function __construct($configuration = array()) + { + $this->configuration = $configuration; + } + /** * Builds the form. * @@ -30,6 +44,16 @@ class RemoteVideoType extends AbstractType */ public function buildForm(FormBuilderInterface $builder, array $options) { + $choices = array(); + if (count($this->configuration)) { + foreach($this->configuration as $config => $enabled) { + if (!$enabled) { + continue; + } + $choices[$config] = $config; + } + } + $builder ->add( 'name', @@ -51,11 +75,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) 'type', 'choice', array( - 'choices' => array( - 'youtube' => 'youtube', - 'vimeo' => 'vimeo', - 'dailymotion' => 'dailymotion' - ), + 'choices' => $choices, 'constraints' => array(new NotBlank()), 'required' => true ) diff --git a/Helper/RemoteVideo/RemoteVideoHandler.php b/Helper/RemoteVideo/RemoteVideoHandler.php index 57c2a1e8..8911aa9c 100644 --- a/Helper/RemoteVideo/RemoteVideoHandler.php +++ b/Helper/RemoteVideo/RemoteVideoHandler.php @@ -12,6 +12,11 @@ class RemoteVideoHandler extends AbstractMediaHandler { + /** + * @var array + */ + protected $configuration = array(); + /** * @var string */ @@ -22,6 +27,16 @@ class RemoteVideoHandler extends AbstractMediaHandler */ const TYPE = 'video'; + + /** + * Constructor. Takes the configuration of the RemoveVideoHandler + * @param array $configuration + */ + public function __construct($configuration = array()) + { + $this->configuration = $configuration; + } + /** * @return string */ @@ -43,7 +58,7 @@ public function getType() */ public function getFormType() { - return new RemoteVideoType(); + return new RemoteVideoType($this->configuration); } /** diff --git a/Resources/config/handlers.yml b/Resources/config/handlers.yml index 375ca9ba..09f93462 100644 --- a/Resources/config/handlers.yml +++ b/Resources/config/handlers.yml @@ -15,6 +15,7 @@ services: kunstmaan_media.media_handlers.remote_video: class: "%kunstmaan_media.media_handler.remote_video.class%" + arguments: ["%kunstmaan_media.remote_video%"] tags: - { name: 'kunstmaan_media.media_handler' }