BooleanType.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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\Extension\Core\Type\ChoiceType as FormChoiceType;
  13. use Symfony\Component\Translation\TranslatorInterface;
  14. use Symfony\Component\OptionsResolver\OptionsResolverInterface;
  15. class BooleanType extends FormChoiceType
  16. {
  17. const TYPE_YES = 1;
  18. const TYPE_NO = 2;
  19. protected $translator;
  20. /**
  21. * @param \Symfony\Component\Translation\TranslatorInterface $translator
  22. */
  23. public function __construct(TranslatorInterface $translator)
  24. {
  25. $this->translator = $translator;
  26. }
  27. /**
  28. * {@inheritDoc}
  29. */
  30. public function setDefaultOptions(OptionsResolverInterface $resolver)
  31. {
  32. parent::setDefaultOptions($resolver);
  33. $resolver->setDefaults(array(
  34. 'choices' => array(
  35. self::TYPE_YES => $this->translator->trans('label_type_yes', array(), 'SonataAdminBundle'),
  36. self::TYPE_NO => $this->translator->trans('label_type_no', array(), 'SonataAdminBundle')
  37. )
  38. ));
  39. }
  40. /**
  41. * {@inheritDoc}
  42. */
  43. public function getName()
  44. {
  45. return 'sonata_type_boolean';
  46. }
  47. }