ChoiceTypeExtension.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. $resolver->setOptional(array('sortable'));
  30. }
  31. /**
  32. * {@inheritdoc}
  33. */
  34. public function buildView(FormView $view, FormInterface $form, array $options)
  35. {
  36. $view->vars['sortable'] = array_key_exists('sortable', $options) && $options['sortable'];
  37. }
  38. /**
  39. * Returns the name of the type being extended.
  40. *
  41. * @return string The name of the type being extended
  42. */
  43. public function getExtendedType()
  44. {
  45. return 'choice';
  46. }
  47. }