1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?php
- /*
- * This file is part of the Sonata Project package.
- *
- * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
- namespace Sonata\AdminBundle\Form\Extension;
- use Symfony\Component\Form\AbstractTypeExtension;
- use Symfony\Component\Form\FormInterface;
- use Symfony\Component\Form\FormView;
- use Symfony\Component\OptionsResolver\OptionsResolver;
- use Symfony\Component\OptionsResolver\OptionsResolverInterface;
- /**
- * @author Amine Zaghdoudi <amine.zaghdoudi@ekino.com>
- */
- class ChoiceTypeExtension extends AbstractTypeExtension
- {
- /**
- * NEXT_MAJOR: Remove method, when bumping requirements to SF 2.7+.
- *
- * {@inheritdoc}
- */
- public function setDefaultOptions(OptionsResolverInterface $resolver)
- {
- $this->configureOptions($resolver);
- }
- /**
- * {@inheritdoc}
- */
- public function configureOptions(OptionsResolver $resolver)
- {
- $optionalOptions = array('sortable');
- if (method_exists($resolver, 'setDefined')) {
- $resolver->setDefined($optionalOptions);
- } else {
- // To keep Symfony <2.6 support
- $resolver->setOptional($optionalOptions);
- }
- }
- /**
- * {@inheritdoc}
- */
- public function buildView(FormView $view, FormInterface $form, array $options)
- {
- $view->vars['sortable'] = array_key_exists('sortable', $options) && $options['sortable'];
- }
- /**
- * {@inheritdoc}
- */
- public function getExtendedType()
- {
- /*
- * NEXT_MAJOR: Remove when dropping Symfony <2.8 support. It should
- * simply be return 'Symfony\Component\Form\Extension\Core\Type\ChoiceType';
- */
- return method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix')
- ? 'Symfony\Component\Form\Extension\Core\Type\ChoiceType'
- : 'choice';
- }
- }
|