|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the GenemuFormBundle package. |
| 5 | + * |
| 6 | + * (c) Olivier Chauvel <[email protected]> |
| 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 Genemu\Bundle\FormBundle\Form\JQuery\Type; |
| 13 | + |
| 14 | +use Symfony\Component\Form\AbstractType; |
| 15 | +use Symfony\Component\Form\FormView; |
| 16 | +use Symfony\Component\Form\FormInterface; |
| 17 | +use Symfony\Component\OptionsResolver\OptionsResolver; |
| 18 | +use Symfony\Component\OptionsResolver\Options; |
| 19 | + |
| 20 | +/** |
| 21 | + * Select2CurrencyType to JQueryLib |
| 22 | + * |
| 23 | + * @author Bilal Amarni <[email protected]> |
| 24 | + * @author Chris Tickner <[email protected]> |
| 25 | + * @author Benjamin Schumacher <[email protected]> |
| 26 | + */ |
| 27 | +class Select2CurrencyType extends AbstractType |
| 28 | +{ |
| 29 | + private $configs; |
| 30 | + |
| 31 | + public function __construct(array $configs = array()) |
| 32 | + { |
| 33 | + $this->configs = $configs; |
| 34 | + } |
| 35 | + |
| 36 | + /** |
| 37 | + * {@inheritdoc} |
| 38 | + */ |
| 39 | + public function buildView(FormView $view, FormInterface $form, array $options) |
| 40 | + { |
| 41 | + $view->vars['configs'] = $options['configs']; |
| 42 | + |
| 43 | + // Adds a custom block prefix |
| 44 | + array_splice( |
| 45 | + $view->vars['block_prefixes'], |
| 46 | + array_search($this->getName(), $view->vars['block_prefixes']), |
| 47 | + 0, |
| 48 | + 'genemu_jqueryselect2' |
| 49 | + ); |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * {@inheritdoc} |
| 54 | + */ |
| 55 | + public function configureOptions(OptionsResolver $resolver) |
| 56 | + { |
| 57 | + $defaults = $this->configs; |
| 58 | + $resolver |
| 59 | + ->setDefaults(array( |
| 60 | + 'configs' => $defaults, |
| 61 | + 'transformer' => null, |
| 62 | + )) |
| 63 | + ->setNormalizer( |
| 64 | + 'configs', |
| 65 | + function (Options $options, $configs) use ($defaults) { |
| 66 | + return array_merge($defaults, $configs); |
| 67 | + } |
| 68 | + ) |
| 69 | + ; |
| 70 | + } |
| 71 | + |
| 72 | + /** |
| 73 | + * {@inheritdoc} |
| 74 | + */ |
| 75 | + public function getParent() |
| 76 | + { |
| 77 | + return 'Symfony\Component\Form\Extension\Core\Type\CurrencyType'; |
| 78 | + } |
| 79 | + |
| 80 | + /** |
| 81 | + * {@inheritdoc} |
| 82 | + */ |
| 83 | + public function getName() |
| 84 | + { |
| 85 | + return 'genemu_jqueryselect2_currency'; |
| 86 | + } |
| 87 | + |
| 88 | + /** |
| 89 | + * {@inheritdoc} |
| 90 | + */ |
| 91 | + public function getBlockPrefix() |
| 92 | + { |
| 93 | + return 'genemu_jqueryselect2_currency'; |
| 94 | + } |
| 95 | +} |
0 commit comments