From ca88f0c95137d83756457b809240842c29432194 Mon Sep 17 00:00:00 2001 From: Kim Ausloos Date: Thu, 18 Sep 2014 17:12:30 +0200 Subject: [PATCH 1/2] Make remote video services configurable --- DependencyInjection/Configuration.php | 8 +++++ .../KunstmaanMediaExtension.php | 1 + Form/RemoteVideo/RemoteVideoType.php | 30 +++++++++++++++---- Helper/RemoteVideo/RemoteVideoHandler.php | 17 ++++++++++- Resources/config/handlers.yml | 1 + 5 files changed, 51 insertions(+), 6 deletions(-) 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..925ee814 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' } From 9a1a3311721bcdf80c34639e72c7d8f21123dec8 Mon Sep 17 00:00:00 2001 From: Kim Ausloos Date: Fri, 19 Sep 2014 09:58:36 +0200 Subject: [PATCH 2/2] Typo --- Form/RemoteVideo/RemoteVideoType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Form/RemoteVideo/RemoteVideoType.php b/Form/RemoteVideo/RemoteVideoType.php index 925ee814..42dbd926 100644 --- a/Form/RemoteVideo/RemoteVideoType.php +++ b/Form/RemoteVideo/RemoteVideoType.php @@ -75,7 +75,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) 'type', 'choice', array( - 'choices' => choices, + 'choices' => $choices, 'constraints' => array(new NotBlank()), 'required' => true )