|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Copyright 2014 SURFnet bv |
|
5
|
|
|
* |
|
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
7
|
|
|
* you may not use this file except in compliance with the License. |
|
8
|
|
|
* You may obtain a copy of the License at |
|
9
|
|
|
* |
|
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
11
|
|
|
* |
|
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15
|
|
|
* See the License for the specific language governing permissions and |
|
16
|
|
|
* limitations under the License. |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
namespace Surfnet\StepupBundle\Form\Type; |
|
20
|
|
|
|
|
21
|
|
|
use Surfnet\StepupBundle\Form\ChoiceList\LocaleChoiceList; |
|
22
|
|
|
use Symfony\Component\Form\AbstractType; |
|
23
|
|
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; |
|
24
|
|
|
use Symfony\Component\Form\Extension\Core\Type\SubmitType; |
|
25
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
|
26
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
|
27
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolverInterface; |
|
28
|
|
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; |
|
29
|
|
|
|
|
30
|
|
|
final class SwitchLocaleType extends AbstractType |
|
31
|
|
|
{ |
|
32
|
|
|
/** |
|
33
|
|
|
* @var \Surfnet\StepupBundle\Form\ChoiceList\LocaleChoiceList |
|
34
|
|
|
*/ |
|
35
|
|
|
private $localeChoiceList; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var \Symfony\Component\Routing\Generator\UrlGeneratorInterface |
|
39
|
|
|
*/ |
|
40
|
|
|
private $urlGenerator; |
|
41
|
|
|
|
|
42
|
|
|
public function __construct(LocaleChoiceList $localeChoiceList, UrlGeneratorInterface $urlGenerator) |
|
43
|
|
|
{ |
|
44
|
|
|
$this->localeChoiceList = $localeChoiceList; |
|
45
|
|
|
$this->urlGenerator = $urlGenerator; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function buildForm(FormBuilderInterface $builder, array $options) |
|
49
|
|
|
{ |
|
50
|
|
|
$builder->setAction($this->urlGenerator->generate($options['route'], $options['route_parameters'])); |
|
51
|
|
|
$builder->setMethod('POST'); |
|
52
|
|
|
$builder->add('locale', ChoiceType::class, [ |
|
53
|
|
|
'label' => /** @Ignore */ false, |
|
54
|
|
|
'required' => true, |
|
55
|
|
|
'choices' => $this->localeChoiceList->create(), |
|
56
|
|
|
'attr' => [ 'class' => 'fa-language' ], |
|
57
|
|
|
]); |
|
58
|
|
|
$builder->add('switch', SubmitType::class, [ |
|
59
|
|
|
'label' => 'stepup_middleware_client.form.switch_locale.switch', |
|
60
|
|
|
'attr' => [ 'class' => 'btn btn-default' ], |
|
61
|
|
|
]); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function configureOptions(OptionsResolver $resolver) |
|
65
|
|
|
{ |
|
66
|
|
|
$resolver->setDefaults([ |
|
67
|
|
|
'route' => null, |
|
68
|
|
|
'route_parameters' => [], |
|
69
|
|
|
'data_class' => 'Surfnet\StepupBundle\Command\SwitchLocaleCommand', |
|
70
|
|
|
]); |
|
71
|
|
|
|
|
72
|
|
|
$resolver->setRequired(['route']); |
|
73
|
|
|
|
|
74
|
|
|
$resolver->setAllowedTypes('route', 'string'); |
|
75
|
|
|
$resolver->setAllowedTypes('route_parameters', 'array'); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function getBlockPrefix() |
|
79
|
|
|
{ |
|
80
|
|
|
return 'stepup_switch_locale'; |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|