MenuTranslationType::configureOptions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Php DDD Standard project.
5
 *
6
 * Copyright (c) 2017 LIN3S <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace LIN3S\CMSKernel\Infrastructure\Symfony\Form\Type\Menu;
13
14
use LIN3S\CMSKernel\Infrastructure\Symfony\Form\Type\MenuTreeType;
15
use Symfony\Component\Form\AbstractType;
16
use Symfony\Component\Form\Extension\Core\Type\TextType;
17
use Symfony\Component\Form\FormBuilderInterface;
18
use Symfony\Component\OptionsResolver\OptionsResolver;
19
20
/**
21
 * @author Beñat Espiña <[email protected]>
22
 */
23
class MenuTranslationType extends AbstractType
24
{
25
    private $locale;
26
    private $menuId;
27
28
    public function buildForm(FormBuilderInterface $builder, array $options)
29
    {
30
        $this->locale = $options['locale'];
31
        $this->menuId = isset($options['menu_id']) ? $options['menu_id'] : null;
32
33
        $builder
34
            ->add('name', TextType::class)
35
            ->add('items', MenuTreeType::class, [
36
                'required' => false,
37
                'locale'   => $this->locale,
38
                'menu_id'  => $this->menuId,
39
            ]);
40
    }
41
42
    public function configureOptions(OptionsResolver $resolver)
43
    {
44
        $resolver
45
            ->setRequired('locale')
46
            ->setDefined('menu_id');
47
    }
48
}
49