Completed
Pull Request — 5.0 (#2163)
by Kevin
13:16
created

MediaBundle/Form/RemoteVideo/RemoteVideoType.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Kunstmaan\MediaBundle\Form\RemoteVideo;
4
5
use Kunstmaan\MediaBundle\Form\AbstractRemoteType;
6
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
7
use Symfony\Component\Form\FormBuilderInterface;
8
use Symfony\Component\OptionsResolver\OptionsResolver;
9
use Symfony\Component\Validator\Constraints\NotBlank;
10
11
class RemoteVideoType extends AbstractRemoteType
12
{
13
    /**
14
     * Builds the form.
15
     *
16
     * This method is called for each type in the hierarchy starting form the
17
     * top most type. Type extensions can further modify the form.
18
     *
19
     * @param FormBuilderInterface $builder The form builder
20
     * @param array                $options The options
21
     *
22
     * @see FormTypeExtensionInterface::buildForm()
23
     */
24 View Code Duplication
    public function buildForm(FormBuilderInterface $builder, array $options)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
25
    {
26
        parent::buildForm($builder, $options);
27
28
        $builder
29
            ->add(
30
                'type',
31
                ChoiceType::class,
32
                array(
33
                    'label'       => 'media.form.remote_video.type.label',
34
                    'choices'     => $this->getRemoteVideoChoices($options['configuration']),
35
                    'constraints' => array(new NotBlank()),
36
                    'required'    => true
37
                )
38
            );
39
    }
40
41
    protected function getRemoteVideoChoices($configuration)
42
    {
43
        $choices = array();
44
        if (count($configuration)) {
45
            foreach ($configuration as $config => $enabled) {
46
                if (!$enabled) {
47
                    continue;
48
                }
49
                $choices[$config] = $config;
50
            }
51
        }
52
53
        return $choices;
54
    }
55
56
    /**
57
     * Returns the name of this type.
58
     *
59
     * @return string The name of this type
60
     */
61
    public function getBlockPrefix()
62
    {
63
        return 'kunstmaan_mediabundle_videotype';
64
    }
65
66
    /**
67
     * Sets the default options for this type.
68
     *
69
     * @param OptionsResolver $resolver The resolver for the options.
70
     */
71
    public function configureOptions(OptionsResolver $resolver)
72
    {
73
        $resolver->setDefaults(
74
            array(
75
                'data_class' => 'Kunstmaan\MediaBundle\Helper\RemoteVideo\RemoteVideoHelper',
76
                'configuration' => array()
77
            )
78
        );
79
    }
80
}
81