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
|
|
|
|