From 5a33c2ca2ec64fdff79e86834009134eda7db760 Mon Sep 17 00:00:00 2001 From: Abdellatif Ait boudad Date: Wed, 1 Apr 2015 12:46:44 +0100 Subject: [PATCH] [Form][choice] added choice_translation_domain to avoid trans options. --- UPGRADE-2.7.md | 246 ++++++++++-------- .../Doctrine/Form/Type/DoctrineType.php | 1 + .../views/Form/form_div_layout.html.twig | 4 +- .../views/Form/choice_widget_options.html.php | 6 +- src/Symfony/Component/Form/CHANGELOG.md | 3 +- .../Form/Extension/Core/Type/ChoiceType.php | 17 ++ .../Form/Extension/Core/Type/CountryType.php | 1 + .../Form/Extension/Core/Type/CurrencyType.php | 1 + .../Form/Extension/Core/Type/LanguageType.php | 1 + .../Form/Extension/Core/Type/LocaleType.php | 1 + .../Form/Extension/Core/Type/TimezoneType.php | 1 + .../Tests/AbstractBootstrap3LayoutTest.php | 12 +- .../Form/Tests/AbstractLayoutTest.php | 12 +- .../Extension/Core/Type/ChoiceTypeTest.php | 45 ++++ 14 files changed, 228 insertions(+), 123 deletions(-) diff --git a/UPGRADE-2.7.md b/UPGRADE-2.7.md index cb00c115e74c..c7a6590fd264 100644 --- a/UPGRADE-2.7.md +++ b/UPGRADE-2.7.md @@ -15,7 +15,7 @@ Router `foo%bar%2` which would be compiled to `$foo % $bar % 2` in 2.6 but in 2.7 you would get an error if `bar` parameter doesn't exist or unexpected result otherwise. - + Form ---- @@ -23,14 +23,14 @@ Form AbstractType or AbstractExtensionType has been deprecated in favor of overriding the new "configureOptions" method. - The method "setDefaultOptions(OptionsResolverInterface $resolver)" will + The method "setDefaultOptions(OptionsResolverInterface $resolver)" will be renamed in Symfony 3.0 to "configureOptions(OptionsResolver $resolver)". Before: ```php use Symfony\Component\OptionsResolver\OptionsResolverInterface; - + class TaskType extends AbstractType { // ... @@ -47,7 +47,7 @@ Form ```php use Symfony\Component\OptionsResolver\OptionsResolver; - + class TaskType extends AbstractType { // ... @@ -59,12 +59,12 @@ Form } } ``` - + * The "choice_list" option of ChoiceType was deprecated. You should use "choices_as_values" or "choice_loader" now. - + Before: - + ```php $form->add('status', 'choice', array( 'choice_list' => new ObjectChoiceList(array( @@ -74,9 +74,9 @@ Form )), )); ``` - + After: - + ```php $form->add('status', 'choice', array( 'choices' => array( @@ -87,13 +87,13 @@ Form 'choices_as_values' => true, )); ``` - + * You should flip the keys and values of the "choices" option in ChoiceType and set the "choices_as_values" option to `true`. The default value of that option will be switched to `true` in Symfony 3.0. - + Before: - + ```php $form->add('status', 'choice', array( 'choices' => array( @@ -103,9 +103,9 @@ Form )), )); ``` - + After: - + ```php $form->add('status', 'choice', array( 'choices' => array( @@ -116,64 +116,64 @@ Form 'choices_as_values' => true, )); ``` - + * `Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface` was deprecated and will be removed in Symfony 3.0. You should use `Symfony\Component\Form\ChoiceList\ChoiceListInterface` instead. - + Before: - + ```php use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface; - + public function doSomething(ChoiceListInterface $choiceList) { // ... } ``` - + After: - + ```php use Symfony\Component\Form\ChoiceList\ChoiceListInterface; - + public function doSomething(ChoiceListInterface $choiceList) { // ... } ``` - + * `Symfony\Component\Form\Extension\Core\ChoiceList\View\ChoiceView` was deprecated and will be removed in Symfony 3.0. You should use `Symfony\Component\Form\ChoiceList\View\ChoiceView` instead. - + Note that the order of the arguments passed to the constructor was inverted. - + Before: - + ```php use Symfony\Component\Form\Extension\Core\ChoiceList\View\ChoiceView; - + $view = new ChoiceView($data, 'value', 'Label'); ``` - + After: - + ```php use Symfony\Component\Form\ChoiceList\View\ChoiceView; - + $view = new ChoiceView('Label', 'value', $data); ``` - + * `Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceList` was deprecated and will be removed in Symfony 3.0. You should use `Symfony\Component\Form\ChoiceList\Factory\DefaultChoiceListFactory` instead. - + Before: - + ```php use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceList; - + $choiceList = new ChoiceList( array(Status::ENABLED, Status::DISABLED, Status::IGNORED), array('Enabled', 'Disabled', 'Ignored'), @@ -181,19 +181,19 @@ Form array(Status::ENABLED), ); ``` - + After: - + ```php use Symfony\Component\Form\ChoiceList\Factory\DefaultChoiceListFactory; - + $factory = new DefaultChoiceListFactory(); - + $choices = array(Status::ENABLED, Status::DISABLED, Status::IGNORED); $labels = array('Enabled', 'Disabled', 'Ignored'); - + $choiceList = $factory->createListFromChoices($choices); - + $choiceListView = $factory->createView( $choiceList, // Preferred choices @@ -204,75 +204,75 @@ Form } ); ``` - + * `Symfony\Component\Form\Extension\Core\ChoiceList\LazyChoiceList` was deprecated and will be removed in Symfony 3.0. You should use `Symfony\Component\Form\ChoiceList\Factory\DefaultChoiceListFactory::createListFromLoader()` - together with an implementation of + together with an implementation of `Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface` instead. - + Before: - + ```php use Symfony\Component\Form\Extension\Core\ChoiceList\LazyChoiceList; - + class MyLazyChoiceList extends LazyChoiceList { public function loadChoiceList() { // load $choiceList - + return $choiceList; } } - + $choiceList = new MyLazyChoiceList(); ``` - + After: - + ```php use Symfony\Component\Form\ChoiceList\Factory\DefaultChoiceListFactory; use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface; - + class MyChoiceLoader implements ChoiceLoaderInterface { // ... } - + $factory = new DefaultChoiceListFactory(); - + $choiceList = $factory->createListFromLoader(new MyChoiceLoader()); ``` - + * `Symfony\Component\Form\Extension\Core\ChoiceList\ObjectChoiceList` was deprecated and will be removed in Symfony 3.0. You should use `Symfony\Component\Form\ChoiceList\Factory\DefaultChoiceListFactory` instead. - + Before: - + ```php use Symfony\Component\Form\Extension\Core\ChoiceList\ObjectChoiceList; - + $choiceList = new ObjectChoiceList( array(Status::getInstance(Status::ENABLED), Status::getInstance(Status::DISABLED)), // Label property 'name' ); ``` - + After: - + ```php use Symfony\Component\Form\ChoiceList\Factory\DefaultChoiceListFactory; - + $factory = new DefaultChoiceListFactory(); - + $choiceList = $factory->createListFromChoices(array( - Status::getInstance(Status::ENABLED), - Status::getInstance(Status::DISABLED), + Status::getInstance(Status::ENABLED), + Status::getInstance(Status::DISABLED), )); - + $choiceListView = $factory->createView( $choiceList, // Preferred choices @@ -281,34 +281,34 @@ Form 'name' ); ``` - + * `Symfony\Component\Form\Extension\Core\ChoiceList\SimpleChoiceList` was deprecated and will be removed in Symfony 3.0. You should use `Symfony\Component\Form\ChoiceList\Factory\DefaultChoiceListFactory` instead. - + Before: - + ```php use Symfony\Component\Form\Extension\Core\ChoiceList\SimpleChoiceList; - + $choiceList = new SimpleChoiceList(array( Status::ENABLED => 'Enabled', Status::DISABLED => 'Disabled', )); ``` - + After: - + ```php use Symfony\Component\Form\ChoiceList\Factory\DefaultChoiceListFactory; - + $factory = new DefaultChoiceListFactory(); - + $choices = array(Status::ENABLED, Status::DISABLED); $labels = array('Enabled', 'Disabled'); - + $choiceList = $factory->createListFromChoices($choices); - + $choiceListView = $factory->createView( $choiceList, // Preferred choices @@ -319,116 +319,152 @@ Form } ); ``` - + * The "property" option of `DoctrineType` was deprecated. You should use the new inherited option "choice_label" instead, which has the same effect. - + Before: - + ```php $form->add('tags', 'entity', array( 'class' => 'Acme\Entity\MyTag', 'property' => 'name', )) ``` - + After: - + ```php $form->add('tags', 'entity', array( 'class' => 'Acme\Entity\MyTag', 'choice_label' => 'name', )) ``` - + * The "loader" option of `DoctrineType` was deprecated and will be removed in Symfony 3.0. You should override the `getLoader()` method instead in a custom type. - + Before: - + ```php $form->add('tags', 'entity', array( 'class' => 'Acme\Entity\MyTag', 'loader' => new MyEntityLoader(), )) ``` - + After: - + class MyEntityType extends DoctrineType { // ... - + public function getLoader() { return new MyEntityLoader(); } } - + * `Symfony\Bridge\Doctrine\Form\ChoiceList\EntityChoiceList` was deprecated and will be removed in Symfony 3.0. You should use `Symfony\Bridge\Doctrine\Form\ChoiceList\DoctrineChoiceLoader` instead. - + Before: - + ```php use Symfony\Component\Form\Extension\Core\ChoiceList\SimpleChoiceList; - + $choiceList = new EntityChoiceList($em, 'Acme\Entity\MyEntity'); ``` - + After: - + ```php use Symfony\Component\Form\ChoiceList\Factory\DefaultChoiceListFactory; - + $factory = new DefaultChoiceListFactory(); - + $choices = array(Status::ENABLED, Status::DISABLED); $labels = array('Enabled', 'Disabled'); - + $choiceLoader = new DoctrineChoiceLoader($factory, $em, 'Acme\Entity\MyEntity'); $choiceList = $factory->createListFromLoader($choiceLoader); ``` - + * Passing a query builder closure to `ORMQueryBuilderLoader` was deprecated and will not be supported anymore in Symfony 3.0. You should pass resolved query builders only. - + Consequently, the arguments `$manager` and `$class` of `ORMQueryBuilderLoader` have been deprecated as well. - + Note that the "query_builder" option of `DoctrineType` *does* support closures, but the closure is now resolved in the type instead of in the loader. - + Before: - + ``` use Symfony\Bridge\Doctrine\Form\ChoiceList\ORMQueryBuilderLoader; - + $queryBuilder = function () { // return QueryBuilder }; $loader = new ORMQueryBuilderLoader($queryBuilder); ``` - + After: - + ``` use Symfony\Bridge\Doctrine\Form\ChoiceList\ORMQueryBuilderLoader; - + // create $queryBuilder $loader = new ORMQueryBuilderLoader($queryBuilder); ``` - - * The classes `ChoiceToBooleanArrayTransformer`, + + * The classes `ChoiceToBooleanArrayTransformer`, `ChoicesToBooleanArrayTransformer`, `FixRadioInputListener` and - `FixCheckboxInputListener` were deprecated and will be removed in Symfony 3.0. - Their functionality is covered by the new classes `RadioListMapper` and + `FixCheckboxInputListener` were deprecated and will be removed in Symfony 3.0. + Their functionality is covered by the new classes `RadioListMapper` and `CheckboxListMapper`. + * The ability to translate Doctrine type entries by the translator component + is now disabled by default and to enable it you must explicitly set the option + "choice_translation_domain" to true + + Before: + + ``` + $form->add('products', 'entity', array( + 'class' => 'AppBundle/Entity/Product', + )); + ``` + + After: + + ``` + $form->add('products', 'entity', array( + 'class' => 'AppBundle/Entity/Product', + 'choice_translation_domain' => true, + )); + ``` + + * In the block `choice_widget_options` the `translation_domain` has been replaced + with the `choice_translation_domain` option. + + Before: + + ```jinja + {{ choice.label|trans({}, translation_domain) }} + ``` + + After: + + ```jinja + {{ choice_translation_domain is sameas(false) ? choice.label : choice.label|trans({}, choice_translation_domain) }} + ``` + Serializer ---------- diff --git a/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php b/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php index a478574190d6..acc6d52a92dd 100644 --- a/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php +++ b/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php @@ -292,6 +292,7 @@ public function configureOptions(OptionsResolver $resolver) 'choice_name' => $choiceName, 'choice_value' => $choiceValue, 'id_reader' => null, // internal + 'choice_translation_domain' => false, )); $resolver->setRequired(array('class')); diff --git a/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig b/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig index df0e571602ec..de54d49c3045 100644 --- a/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig +++ b/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig @@ -74,13 +74,13 @@ {%- block choice_widget_options -%} {% for group_label, choice in options %} {%- if choice is iterable -%} - + {% set options = choice %} {{- block('choice_widget_options') -}} {%- else -%} {% set attr = choice.attr %} - + {%- endif -%} {% endfor %} {%- endblock choice_widget_options -%} diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/choice_widget_options.html.php b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/choice_widget_options.html.php index 81402efffb10..a0363cc5a47b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/choice_widget_options.html.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/choice_widget_options.html.php @@ -2,12 +2,12 @@ $translatorHelper = $view['translator']; // outside of the loop for performance reasons! ?> - $choice): ?> + $choice): ?> - + block($form, 'choice_widget_options', array('choices' => $choice)) ?> - + diff --git a/src/Symfony/Component/Form/CHANGELOG.md b/src/Symfony/Component/Form/CHANGELOG.md index 0ddc660b218d..b1387bb2e639 100644 --- a/src/Symfony/Component/Form/CHANGELOG.md +++ b/src/Symfony/Component/Form/CHANGELOG.md @@ -4,6 +4,7 @@ CHANGELOG 2.7.0 ----- + * added option "choice_translation_domain" to ChoiceType. * deprecated option "precision" in favor of "scale" * deprecated the overwriting of AbstractType::setDefaultOptions() in favor of overwriting AbstractType::configureOptions(). * deprecated the overwriting of AbstractTypeExtension::setDefaultOptions() in favor of overwriting AbstractTypeExtension::configureOptions(). @@ -16,7 +17,7 @@ CHANGELOG * deprecated ChoiceToBooleanArrayTransformer and ChoicesToBooleanArrayTransformer * deprecated FixCheckboxInputListener and FixRadioInputListener * deprecated the "choice_list" option of ChoiceType - * added new options to ChoiceType: + * added new options to ChoiceType: * "choices_as_values" * "choice_loader" * "choice_label" diff --git a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php index a597e1d4f412..09d81ee7afd7 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php @@ -158,6 +158,11 @@ public function buildForm(FormBuilderInterface $builder, array $options) */ public function buildView(FormView $view, FormInterface $form, array $options) { + $choiceTranslationDomain = $options['choice_translation_domain']; + if ($view->parent && null === $choiceTranslationDomain) { + $choiceTranslationDomain = $view->vars['translation_domain']; + } + /** @var ChoiceListView $choiceListView */ $choiceListView = $form->getConfig()->hasAttribute('choice_list_view') ? $form->getConfig()->getAttribute('choice_list_view') @@ -170,6 +175,7 @@ public function buildView(FormView $view, FormInterface $form, array $options) 'choices' => $choiceListView->choices, 'separator' => '-------------------', 'placeholder' => null, + 'choice_translation_domain' => $choiceTranslationDomain, )); // The decision, whether a choice is selected, is potentially done @@ -295,6 +301,14 @@ public function configureOptions(OptionsResolver $resolver) return $options['expanded']; }; + $choiceTranslationDomainNormalizer = function (Options $options, $choiceTranslationDomain) { + if (true === $choiceTranslationDomain) { + return $options['translation_domain']; + } + + return $choiceTranslationDomain; + }; + $resolver->setDefaults(array( 'multiple' => false, 'expanded' => false, @@ -317,14 +331,17 @@ public function configureOptions(OptionsResolver $resolver) // is manually set to an object. // See https://github.com/symfony/symfony/pull/5582 'data_class' => null, + 'choice_translation_domain' => true, )); $resolver->setNormalizer('choice_list', $choiceListNormalizer); $resolver->setNormalizer('empty_value', $placeholderNormalizer); $resolver->setNormalizer('placeholder', $placeholderNormalizer); + $resolver->setNormalizer('choice_translation_domain', $choiceTranslationDomainNormalizer); $resolver->setAllowedTypes('choice_list', array('null', 'Symfony\Component\Form\ChoiceList\ChoiceListInterface')); $resolver->setAllowedTypes('choices', array('null', 'array', '\Traversable')); + $resolver->setAllowedTypes('choice_translation_domain', array('null', 'bool', 'string')); $resolver->setAllowedTypes('choices_as_values', 'bool'); $resolver->setAllowedTypes('choice_loader', array('null', 'Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface')); $resolver->setAllowedTypes('choice_label', array('null', 'callable', 'string', 'Symfony\Component\PropertyAccess\PropertyPath')); diff --git a/src/Symfony/Component/Form/Extension/Core/Type/CountryType.php b/src/Symfony/Component/Form/Extension/Core/Type/CountryType.php index e6231c596b25..30ee0a0f9e89 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/CountryType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/CountryType.php @@ -24,6 +24,7 @@ public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( 'choices' => Intl::getRegionBundle()->getCountryNames(), + 'choice_translation_domain' => false, )); } diff --git a/src/Symfony/Component/Form/Extension/Core/Type/CurrencyType.php b/src/Symfony/Component/Form/Extension/Core/Type/CurrencyType.php index 9d77b763818d..b473d139e656 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/CurrencyType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/CurrencyType.php @@ -24,6 +24,7 @@ public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( 'choices' => Intl::getCurrencyBundle()->getCurrencyNames(), + 'choice_translation_domain' => false, )); } diff --git a/src/Symfony/Component/Form/Extension/Core/Type/LanguageType.php b/src/Symfony/Component/Form/Extension/Core/Type/LanguageType.php index 4bd09d26e914..9d071eb8b03e 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/LanguageType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/LanguageType.php @@ -24,6 +24,7 @@ public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( 'choices' => Intl::getLanguageBundle()->getLanguageNames(), + 'choice_translation_domain' => false, )); } diff --git a/src/Symfony/Component/Form/Extension/Core/Type/LocaleType.php b/src/Symfony/Component/Form/Extension/Core/Type/LocaleType.php index 92a41080e4d4..f09f5a62f1e2 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/LocaleType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/LocaleType.php @@ -24,6 +24,7 @@ public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( 'choices' => Intl::getLocaleBundle()->getLocaleNames(), + 'choice_translation_domain' => false, )); } diff --git a/src/Symfony/Component/Form/Extension/Core/Type/TimezoneType.php b/src/Symfony/Component/Form/Extension/Core/Type/TimezoneType.php index d19fb52fdce7..82c07e2f121b 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/TimezoneType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/TimezoneType.php @@ -30,6 +30,7 @@ public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( 'choices' => self::getTimezones(), + 'choice_translation_domain' => false, )); } diff --git a/src/Symfony/Component/Form/Tests/AbstractBootstrap3LayoutTest.php b/src/Symfony/Component/Form/Tests/AbstractBootstrap3LayoutTest.php index 6cc7edd7a38e..28f576890b09 100644 --- a/src/Symfony/Component/Form/Tests/AbstractBootstrap3LayoutTest.php +++ b/src/Symfony/Component/Form/Tests/AbstractBootstrap3LayoutTest.php @@ -840,7 +840,7 @@ public function testCountry() '/select [@name="name"] [@class="my&class form-control"] - [./option[@value="AT"][@selected="selected"][.="[trans]Austria[/trans]"]] + [./option[@value="AT"][@selected="selected"][.="Austria"]] [count(./option)>200] ' ); @@ -858,7 +858,7 @@ public function testCountryWithPlaceholder() [@name="name"] [@class="my&class form-control"] [./option[@value=""][not(@selected)][not(@disabled)][.="[trans]Select&Country[/trans]"]] - [./option[@value="AT"][@selected="selected"][.="[trans]Austria[/trans]"]] + [./option[@value="AT"][@selected="selected"][.="Austria"]] [count(./option)>201] ' ); @@ -1388,7 +1388,7 @@ public function testLanguage() '/select [@name="name"] [@class="my&class form-control"] - [./option[@value="de"][@selected="selected"][.="[trans]German[/trans]"]] + [./option[@value="de"][@selected="selected"][.="German"]] [count(./option)>200] ' ); @@ -1402,7 +1402,7 @@ public function testLocale() '/select [@name="name"] [@class="my&class form-control"] - [./option[@value="de_AT"][@selected="selected"][.="[trans]German (Austria)[/trans]"]] + [./option[@value="de_AT"][@selected="selected"][.="German (Austria)"]] [count(./option)>200] ' ); @@ -1826,8 +1826,8 @@ public function testTimezone() [@class="my&class form-control"] [not(@required)] [./optgroup - [@label="[trans]Europe[/trans]"] - [./option[@value="Europe/Vienna"][@selected="selected"][.="[trans]Vienna[/trans]"]] + [@label="Europe"] + [./option[@value="Europe/Vienna"][@selected="selected"][.="Vienna"]] ] [count(./optgroup)>10] [count(.//option)>200] diff --git a/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php b/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php index 3bf84d71c82c..5660d2769d6f 100644 --- a/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php +++ b/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php @@ -1016,7 +1016,7 @@ public function testCountry() $this->assertWidgetMatchesXpath($form->createView(), array(), '/select [@name="name"] - [./option[@value="AT"][@selected="selected"][.="[trans]Austria[/trans]"]] + [./option[@value="AT"][@selected="selected"][.="Austria"]] [count(./option)>200] ' ); @@ -1033,7 +1033,7 @@ public function testCountryWithPlaceholder() '/select [@name="name"] [./option[@value=""][not(@selected)][not(@disabled)][.="[trans]Select&Country[/trans]"]] - [./option[@value="AT"][@selected="selected"][.="[trans]Austria[/trans]"]] + [./option[@value="AT"][@selected="selected"][.="Austria"]] [count(./option)>201] ' ); @@ -1557,7 +1557,7 @@ public function testLanguage() $this->assertWidgetMatchesXpath($form->createView(), array(), '/select [@name="name"] - [./option[@value="de"][@selected="selected"][.="[trans]German[/trans]"]] + [./option[@value="de"][@selected="selected"][.="German"]] [count(./option)>200] ' ); @@ -1570,7 +1570,7 @@ public function testLocale() $this->assertWidgetMatchesXpath($form->createView(), array(), '/select [@name="name"] - [./option[@value="de_AT"][@selected="selected"][.="[trans]German (Austria)[/trans]"]] + [./option[@value="de_AT"][@selected="selected"][.="German (Austria)"]] [count(./option)>200] ' ); @@ -1936,8 +1936,8 @@ public function testTimezone() [@name="name"] [not(@required)] [./optgroup - [@label="[trans]Europe[/trans]"] - [./option[@value="Europe/Vienna"][@selected="selected"][.="[trans]Vienna[/trans]"]] + [@label="Europe"] + [./option[@value="Europe/Vienna"][@selected="selected"][.="Vienna"]] ] [count(./optgroup)>10] [count(.//option)>200] diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php index d34d5b218412..791df12d85df 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php @@ -1331,6 +1331,51 @@ public function testPassExpandedToView() $this->assertTrue($view->vars['expanded']); } + public function testPassChoiceTranslationDomainToView() + { + $form = $this->factory->create('choice', null, array( + 'choices' => $this->choices, + )); + $view = $form->createView(); + + $this->assertNull($view->vars['choice_translation_domain']); + } + + public function testChoiceTranslationDomainWithTrueValueToView() + { + $form = $this->factory->create('choice', null, array( + 'choices' => $this->choices, + 'choice_translation_domain' => true, + )); + $view = $form->createView(); + + $this->assertNull($view->vars['choice_translation_domain']); + } + + public function testDefaulChoiceTranslationDomainIsSameAsTranslationDomainToView() + { + $form = $this->factory->create('choice', null, array( + 'choices' => $this->choices, + 'translation_domain' => 'foo', + )); + $view = $form->createView(); + + $this->assertEquals('foo', $view->vars['choice_translation_domain']); + } + + public function testInheritChoiceTranslationDomainFromParent() + { + $view = $this->factory + ->createNamedBuilder('parent', 'form', null, array( + 'translation_domain' => 'domain', + )) + ->add('child', 'choice') + ->getForm() + ->createView(); + + $this->assertEquals('domain', $view['child']->vars['choice_translation_domain']); + } + public function testPlaceholderIsNullByDefaultIfRequired() { $form = $this->factory->create('choice', null, array(