Pārlūkot izejas kodu

Merge pull request #565 from oparadis/fix_translatable

Fix TranslatableChoice to have translations work on expanded=true & mult...
Thomas 13 gadi atpakaļ
vecāks
revīzija
dfbd896038
1 mainītis faili ar 10 papildinājumiem un 20 dzēšanām
  1. 10 20
      Form/Type/TranslatableChoiceType.php

+ 10 - 20
Form/Type/TranslatableChoiceType.php

@@ -54,26 +54,16 @@ class TranslatableChoiceType extends ChoiceType
 
 
     public function buildForm(FormBuilder $builder, array $options)
     public function buildForm(FormBuilder $builder, array $options)
     {
     {
-        parent::buildForm($builder, $options);
-
-        $builder->setAttribute('catalogue', $options['catalogue']);
-    }
-
-    public function buildView(FormView $view, FormInterface $form)
-    {
-        parent::buildView($view, $form);
-
-        $choices = array();
-        $catalogue = $form->getAttribute('catalogue');
-
-        foreach ($view->get('choices') as $name => $value) {
-            $choices[$name] = $this->translator->trans($value, array(), $catalogue);
+        // translate options before building form
+        foreach ($options['choices'] as $name => $value) {
+            $options['choices'][$name] = $this->translator->trans($value, array(), $options['catalogue']);
         }
         }
-
-        $view->set('choices', $choices);
-        $empty_value = $view->get('empty_value');
-        if (!empty($empty_value)) {
-            $view->set('empty_value', $this->translator->trans($view->get('empty_value'), array(), $catalogue));
+        
+        // translate empty value
+        if (!empty($options['empty_value'])) {
+            $options['empty_value'] = $this->translator->trans($options['empty_value'], array(), $options['catalogue']);
         }
         }
+        
+        parent::buildForm($builder, $options);
     }
     }
-}
+}