From 89609e46221d83caf1ae6fa3eac12bdccc7044d4 Mon Sep 17 00:00:00 2001 From: Seb Date: Wed, 13 Sep 2017 13:44:18 +0200 Subject: [PATCH] add default domain when adding a new translation --- Controller/TranslationController.php | 3 ++- Form/Type/TransUnitType.php | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Controller/TranslationController.php b/Controller/TranslationController.php index 0d469b6e..b908145c 100644 --- a/Controller/TranslationController.php +++ b/Controller/TranslationController.php @@ -2,6 +2,7 @@ namespace Lexik\Bundle\TranslationBundle\Controller; +use Lexik\Bundle\TranslationBundle\Form\Type\TransUnitType; use Lexik\Bundle\TranslationBundle\Storage\StorageInterface; use Lexik\Bundle\TranslationBundle\Util\Csrf\CsrfCheckerTrait; use Symfony\Bundle\FrameworkBundle\Controller\Controller; @@ -89,7 +90,7 @@ public function newAction(Request $request) { $handler = $this->get('lexik_translation.form.handler.trans_unit'); - $form = $this->createForm('Lexik\Bundle\TranslationBundle\Form\Type\TransUnitType', $handler->createFormData(), $handler->getFormOptions()); + $form = $this->createForm(TransUnitType::class, $handler->createFormData(), $handler->getFormOptions()); if ($handler->process($form, $request)) { $message = $this->get('translator')->trans('translations.successfully_added', array(), 'LexikTranslationBundle'); diff --git a/Form/Type/TransUnitType.php b/Form/Type/TransUnitType.php index 7f67e178..38bb6851 100644 --- a/Form/Type/TransUnitType.php +++ b/Form/Type/TransUnitType.php @@ -23,7 +23,10 @@ public function buildForm(FormBuilderInterface $builder, array $options) )); $builder->add('domain', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', array( 'label' => 'translations.domain', - 'choices' => array_combine($options['domains'], $options['domains']), + 'choices' => array_merge( + array_combine($options['default_domain'], $options['default_domain']), + array_combine($options['domains'], $options['domains']) + ), )); $builder->add('translations', 'Symfony\Component\Form\Extension\Core\Type\CollectionType', array( 'entry_type' => 'Lexik\Bundle\TranslationBundle\Form\Type\TranslationType', @@ -48,7 +51,8 @@ public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( 'data_class' => null, - 'domains' => array('messages'), + 'default_domain' => ['messages'], + 'domains' => [], 'translation_class' => null, 'translation_domain' => 'LexikTranslationBundle', ));