Select2Type::configureOptions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 7
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LAG\AdminBundle\Form\Type\Select2;
6
7
use Symfony\Component\Form\AbstractType;
8
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
9
use Symfony\Component\Form\FormInterface;
10
use Symfony\Component\Form\FormView;
11
use Symfony\Component\OptionsResolver\OptionsResolver;
12
13
class Select2Type extends AbstractType
14
{
15
    public function getParent(): string
16
    {
17
        return ChoiceType::class;
18
    }
19
20
    public function configureOptions(OptionsResolver $resolver)
21
    {
22
        $resolver
23
            ->setDefaults([
24
                'select2_options' => [],
25
            ])
26
            ->setAllowedTypes('select2_options', 'array')
27
        ;
28
    }
29
30
    public function buildView(FormView $view, FormInterface $form, array $options)
31
    {
32
        $view->vars['attr']['data-controller'] = 'select2';
33
        $view->vars['attr']['data-options'] = json_encode($options['select2_options']);
34
    }
35
}
36