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