BooleanType.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. public function __construct(TranslatorInterface $translator)
  20. {
  21. $this->translator = $translator;
  22. }
  23. public function getDefaultOptions(array $options)
  24. {
  25. $options = parent::getDefaultOptions($options);
  26. $options['choices'] = array(
  27. self::TYPE_YES => $this->translator->trans('label_type_yes', array(), 'SonataAdminBundle'),
  28. self::TYPE_NO => $this->translator->trans('label_type_no', array(), 'SonataAdminBundle'),
  29. );
  30. return $options;
  31. }
  32. }