]>
Commit | Line | Data |
---|---|---|
4f5b44bd NL |
1 | <?php |
2 | ||
3 | /* | |
4 | * This file is part of the Symfony package. | |
5 | * | |
6 | * (c) Fabien Potencier <fabien@symfony.com> | |
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 Symfony\Component\Form\Extension\Core\Type; | |
13 | ||
14 | use Symfony\Component\Form\AbstractType; | |
15 | use Symfony\Component\Form\FormBuilderInterface; | |
16 | use Symfony\Component\Form\Extension\Core\DataTransformer\PercentToLocalizedStringTransformer; | |
17 | use Symfony\Component\OptionsResolver\OptionsResolverInterface; | |
18 | ||
19 | class PercentType extends AbstractType | |
20 | { | |
21 | /** | |
22 | * {@inheritdoc} | |
23 | */ | |
24 | public function buildForm(FormBuilderInterface $builder, array $options) | |
25 | { | |
26 | $builder->addViewTransformer(new PercentToLocalizedStringTransformer($options['precision'], $options['type'])); | |
27 | } | |
28 | ||
29 | /** | |
30 | * {@inheritdoc} | |
31 | */ | |
32 | public function setDefaultOptions(OptionsResolverInterface $resolver) | |
33 | { | |
34 | $resolver->setDefaults(array( | |
35 | 'precision' => 0, | |
36 | 'type' => 'fractional', | |
37 | 'compound' => false, | |
38 | )); | |
39 | ||
40 | $resolver->setAllowedValues(array( | |
41 | 'type' => array( | |
42 | 'fractional', | |
43 | 'integer', | |
44 | ), | |
45 | )); | |
46 | } | |
47 | ||
48 | /** | |
49 | * {@inheritdoc} | |
50 | */ | |
51 | public function getName() | |
52 | { | |
53 | return 'percent'; | |
54 | } | |
55 | } |