BooleanType.php 1.3 KB

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