BooleanType.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. */
  11. namespace Sonata\AdminBundle\Form\Type;
  12. use Symfony\Component\Form\AbstractType;
  13. use Symfony\Component\Form\FormBuilderInterface;
  14. use Sonata\AdminBundle\Form\DataTransformer\BooleanTypeToBooleanTransformer;
  15. use Symfony\Component\OptionsResolver\OptionsResolverInterface;
  16. class BooleanType extends AbstractType
  17. {
  18. const TYPE_YES = 1;
  19. const TYPE_NO = 2;
  20. /**
  21. * {@inheritDoc}
  22. */
  23. public function buildForm(FormBuilderInterface $builder, array $options)
  24. {
  25. if ($options['transform']) {
  26. $builder->addModelTransformer(new BooleanTypeToBooleanTransformer());
  27. }
  28. }
  29. /**
  30. * {@inheritDoc}
  31. */
  32. public function setDefaultOptions(OptionsResolverInterface $resolver)
  33. {
  34. $resolver->setDefaults(array(
  35. 'catalogue' => 'SonataAdminBundle',
  36. 'choices' => array(
  37. self::TYPE_YES => 'label_type_yes',
  38. self::TYPE_NO => 'label_type_no'
  39. ),
  40. 'transform' => false
  41. ));
  42. }
  43. /**
  44. * {@inheritDoc}
  45. */
  46. public function getParent()
  47. {
  48. return 'sonata_type_translatable_choice';
  49. }
  50. /**
  51. * {@inheritDoc}
  52. */
  53. public function getName()
  54. {
  55. return 'sonata_type_boolean';
  56. }
  57. }