TranslatableChoiceType.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. * @deprecated - use ChoiceType with the translation_domain option instead
  11. */
  12. namespace Sonata\AdminBundle\Form\Type;
  13. use Symfony\Component\Translation\TranslatorInterface;
  14. use Symfony\Component\Form\AbstractType;
  15. use Symfony\Component\Form\FormInterface;
  16. use Symfony\Component\Form\FormView;
  17. use Symfony\Component\OptionsResolver\Options;
  18. use Symfony\Component\OptionsResolver\OptionsResolverInterface;
  19. class TranslatableChoiceType extends AbstractType
  20. {
  21. protected $translator;
  22. /**
  23. * @param \Symfony\Component\Translation\TranslatorInterface $translator
  24. */
  25. public function __construct(TranslatorInterface $translator)
  26. {
  27. $this->translator = $translator;
  28. }
  29. /**
  30. * {@inheritDoc}
  31. */
  32. public function setDefaultOptions(OptionsResolverInterface $resolver)
  33. {
  34. $resolver->setDefaults(array(
  35. 'catalogue' => 'messages',
  36. ));
  37. }
  38. /**
  39. * {@inheritDoc}
  40. */
  41. public function buildView(FormView $view, FormInterface $form, array $options)
  42. {
  43. $view->vars['translation_domain'] = $options['catalogue'];
  44. }
  45. /**
  46. * {@inheritDoc}
  47. */
  48. public function getParent()
  49. {
  50. return 'choice';
  51. }
  52. /**
  53. * {@inheritDoc}
  54. */
  55. public function getName()
  56. {
  57. return 'sonata_type_translatable_choice';
  58. }
  59. }