ChoiceTypeExtension.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /*
  3. * This file is part of the Sonata package.
  4. *
  5. * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Sonata\AdminBundle\Form\Extension;
  11. use Symfony\Component\Form\AbstractTypeExtension;
  12. use Symfony\Component\Form\FormView;
  13. use Symfony\Component\Form\FormInterface;
  14. use Symfony\Component\OptionsResolver\OptionsResolverInterface;
  15. /**
  16. * Class ChoiceTypeExtension
  17. *
  18. * @package Sonata\AdminBundle\Form\Extension
  19. *
  20. * @author Amine Zaghdoudi <amine.zaghdoudi@ekino.com>
  21. */
  22. class ChoiceTypeExtension extends AbstractTypeExtension
  23. {
  24. /**
  25. * {@inheritdoc}
  26. */
  27. public function setDefaultOptions(OptionsResolverInterface $resolver)
  28. {
  29. $optionalOptions = array('sortable');
  30. if (method_exists($resolver, 'setDefined')) {
  31. $resolver->setDefined($optionalOptions);
  32. } else {
  33. // To keep Symfony <2.6 support
  34. $resolver->setOptional($optionalOptions);
  35. }
  36. }
  37. /**
  38. * {@inheritdoc}
  39. */
  40. public function buildView(FormView $view, FormInterface $form, array $options)
  41. {
  42. $view->vars['sortable'] = array_key_exists('sortable', $options) && $options['sortable'];
  43. }
  44. /**
  45. * Returns the name of the type being extended.
  46. *
  47. * @return string The name of the type being extended
  48. */
  49. public function getExtendedType()
  50. {
  51. return 'choice';
  52. }
  53. }