Completed
Push — master ( 49a1ac...de016e )
by Kamil
05:40
created

SelectAttributeValueTranslationsType::getParent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
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 Sylius\Bundle\AttributeBundle\Form\Type\AttributeType\Configuration;
13
14
use Sylius\Bundle\ResourceBundle\Form\Type\FixedCollectionType;
15
use Sylius\Component\Resource\Translation\Provider\TranslationLocaleProviderInterface;
16
use Symfony\Component\Form\AbstractType;
17
use Symfony\Component\OptionsResolver\OptionsResolver;
18
19
/**
20
 * @author Laurent Paganin-Gioanni <[email protected]>
21
 */
22
final class SelectAttributeValueTranslationsType extends AbstractType
23
{
24
    /**
25
     * @var string[]
26
     */
27
    private $definedLocalesCodes;
28
29
    /**
30
     * @var string
31
     */
32
    private $defaultLocaleCode;
33
34
    /**
35
     * @param TranslationLocaleProviderInterface $localeProvider
36
     */
37
    public function __construct(TranslationLocaleProviderInterface $localeProvider)
38
    {
39
        $this->definedLocalesCodes = $localeProvider->getDefinedLocalesCodes();
40
        $this->defaultLocaleCode = $localeProvider->getDefaultLocaleCode();
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function configureOptions(OptionsResolver $resolver): void
47
    {
48
        $resolver->setDefaults([
49
            'entries' => $this->definedLocalesCodes,
50
            'entry_name' => function (string $localeCode): string {
51
                return $localeCode;
52
            },
53
            'entry_options' => function (string $localeCode): array {
54
                return [
55
                    'required' => $localeCode === $this->defaultLocaleCode,
56
                ];
57
            }
58
        ]);
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64
    public function getParent(): string
65
    {
66
        return FixedCollectionType::class;
67
    }
68
69
    /**
70
     * {@inheritdoc}
71
     */
72
    public function getBlockPrefix(): string
73
    {
74
        return 'sylius_select_attribute_value_translations';
75
    }
76
}
77