EqualType.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 EqualType extends FormChoiceType
  16. {
  17. const TYPE_IS_EQUAL = 1;
  18. const TYPE_IS_NOT_EQUAL = 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_IS_EQUAL => $this->translator->trans('label_type_equals', array(), 'SonataAdminBundle'),
  36. self::TYPE_IS_NOT_EQUAL => $this->translator->trans('label_type_not_equals', array(), 'SonataAdminBundle'),
  37. )
  38. ));
  39. }
  40. /**
  41. * {@inheritDoc}
  42. */
  43. public function getParent()
  44. {
  45. return 'choice';
  46. }
  47. /**
  48. * {@inheritDoc}
  49. */
  50. public function getName()
  51. {
  52. return 'sonata_type_equal';
  53. }
  54. }