Skip to content

Commit

Permalink
Merge pull request #167 from kimausloos/master
Browse files Browse the repository at this point in the history
Make remote video configurable
  • Loading branch information
Wim Vandersmissen committed Sep 19, 2014
2 parents 4255286 + 9a1a331 commit 815b8ad
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 6 deletions.
8 changes: 8 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();


Expand Down
1 change: 1 addition & 0 deletions DependencyInjection/KunstmaanMediaExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
30 changes: 25 additions & 5 deletions Form/RemoteVideo/RemoteVideoType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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',
Expand All @@ -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
)
Expand Down
17 changes: 16 additions & 1 deletion Helper/RemoteVideo/RemoteVideoHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
class RemoteVideoHandler extends AbstractMediaHandler
{

/**
* @var array
*/
protected $configuration = array();

/**
* @var string
*/
Expand All @@ -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
*/
Expand All @@ -43,7 +58,7 @@ public function getType()
*/
public function getFormType()
{
return new RemoteVideoType();
return new RemoteVideoType($this->configuration);
}

/**
Expand Down
1 change: 1 addition & 0 deletions Resources/config/handlers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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' }

Expand Down

0 comments on commit 815b8ad

Please sign in to comment.