From 0f9a265a9ca3944d58f1d2ac562b6e2e84d29de2 Mon Sep 17 00:00:00 2001 From: Brokhovetsky Dmitriy Date: Tue, 14 Apr 2015 13:32:33 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=B4=D0=B4=D0=B5=D1=80=D0=B6?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B2=D0=BE=D0=B4=D0=B0?= =?UTF-8?q?=20label'=D0=BE=D0=B2=20=D1=84=D0=BE=D1=80=D0=BC=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Parser/FormTypeParser.php | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/Parser/FormTypeParser.php b/Parser/FormTypeParser.php index 5359aa9..3ae2170 100644 --- a/Parser/FormTypeParser.php +++ b/Parser/FormTypeParser.php @@ -22,6 +22,7 @@ use Symfony\Component\Form\ResolvedFormTypeInterface; use Symfony\Component\OptionsResolver\Exception\MissingOptionsException; use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\Form\Exception\FormException; +use Symfony\Component\Translation\TranslatorInterface; class FormTypeParser implements ParserInterface { @@ -35,6 +36,11 @@ class FormTypeParser implements ParserInterface */ protected $formRegistry; + /** + * @var \Symfony\Component\Translation\TranslatorInterface + */ + protected $translator; + /** * @var array */ @@ -52,9 +58,10 @@ class FormTypeParser implements ParserInterface 'file' => DataTypes::FILE, ); - public function __construct(FormFactoryInterface $formFactory) + public function __construct(FormFactoryInterface $formFactory, TranslatorInterface $translator) { $this->formFactory = $formFactory; + $this->translator = $translator; } /** @@ -124,6 +131,7 @@ class FormTypeParser implements ParserInterface private function parseForm($form) { $parameters = array(); + $domain = $form->getConfig()->getOption('translation_domain'); foreach ($form as $name => $child) { $config = $child->getConfig(); $bestType = ''; @@ -187,7 +195,7 @@ class FormTypeParser implements ParserInterface 'default' => null, 'subType' => $subType, 'required' => $config->getRequired(), - 'description' => ($config->getOption('description')) ? $config->getOption('description'):$config->getOption('label'), + 'description' => $this->getFormDescription($config, $domain), 'readonly' => $config->getDisabled(), 'children' => $children, ); @@ -205,7 +213,7 @@ class FormTypeParser implements ParserInterface 'actualType' => 'string', 'default' => $config->getData(), 'required' => $config->getRequired(), - 'description' => ($config->getOption('description')) ? $config->getOption('description'):$config->getOption('label'), + 'description' => $this->getFormDescription($config, $domain), 'readonly' => $config->getDisabled(), ); } @@ -221,7 +229,7 @@ class FormTypeParser implements ParserInterface 'subType' => $subType, 'default' => $config->getData(), 'required' => $config->getRequired(), - 'description' => ($config->getOption('description')) ? $config->getOption('description'):$config->getOption('label'), + 'description' => $this->getFormDescription($config, $domain), 'readonly' => $config->getDisabled(), ); @@ -330,4 +338,11 @@ class FormTypeParser implements ParserInterface return $choices; } + + private function getFormDescription($config, $domain = null) + { + $descr = $config->getOption('description') ?:$config->getOption('label'); + + return $this->translator->trans($descr, [], $domain); + } }