-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPreferencesFormType.php
More file actions
44 lines (37 loc) · 1.01 KB
/
PreferencesFormType.php
File metadata and controls
44 lines (37 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
namespace SyncEngine\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Intl\Locales;
use Symfony\Component\OptionsResolver\OptionsResolver;
use SyncEngine\Service\Preferences;
class PreferencesFormType extends AbstractType
{
public function __construct(
private readonly Preferences $preferences,
) {}
public function buildForm( FormBuilderInterface $builder, array $options ): void
{
$localeChoices = [];
foreach ( Locales::getNames() as $locale => $name ) {
$label = $name . ' (' . $locale . ')';
$localeChoices[ $label ] = $locale;
}
$builder
->add('locale', ChoiceType::class, [
'row_attr' => [
'class' => 'form-floating mb-3',
],
'choices' => $localeChoices,
]);
}
public function configureOptions( OptionsResolver $resolver ): void
{
$resolver->setDefaults( [
'data' => [
'locale' => $this->preferences->get('locale'),
],
] );
}
}