BooleanType.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. public function setDefaultOptions(OptionsResolverInterface $resolver)
  28. {
  29. parent::setDefaultOptions($resolver);
  30. $resolver->setDefaults(array(
  31. 'choices' => array(
  32. self::TYPE_YES => $this->translator->trans('label_type_yes', array(), 'SonataAdminBundle'),
  33. self::TYPE_NO => $this->translator->trans('label_type_no', array(), 'SonataAdminBundle')
  34. )
  35. ));
  36. }
  37. }