Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #26825 [Form] Add choice_translation_locale option for Intl c…
…hoice types (yceruto, fabpot) This PR was merged into the 4.1-dev branch. Discussion ---------- [Form] Add choice_translation_locale option for Intl choice types | Q | A | ------------- | --- | Branch? | master (4.2) | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | #26737 | License | MIT | Doc PR | symfony/symfony-docs#... This PR adds possibility to show the list of elements for a custom locale different to the current one and proposes also deprecate the `ChoiceLoaderInterface` implementation from all of them, moving it to a separate class. See related issue #26737 for full description and use-case. After: ```php $formBuilder->add('country', CountryType::class, [ 'choice_translation_locale' => 'es', ]); ``` Alternative of #23629 TODO: - [x] Update `UPGRADE-*.md` and `src/**/CHANGELOG.md` files. - [x] Add some tests. Commits ------- 9592fa6 moved feature to 4.1 e250dfa Add choice_translation_locale option for Intl choice types
- Loading branch information
Showing
12 changed files
with
377 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/Symfony/Component/Form/ChoiceList/Loader/IntlCallbackChoiceLoader.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Form\ChoiceList\Loader; | ||
|
||
/** | ||
* Callback choice loader optimized for Intl choice types. | ||
* | ||
* @author Jules Pietri <jules@heahprod.com> | ||
* @author Yonel Ceruto <yonelceruto@gmail.com> | ||
*/ | ||
class IntlCallbackChoiceLoader extends CallbackChoiceLoader | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function loadChoicesForValues(array $values, $value = null) | ||
{ | ||
// Optimize | ||
$values = array_filter($values); | ||
if (empty($values)) { | ||
return array(); | ||
} | ||
|
||
// If no callable is set, values are the same as choices | ||
if (null === $value) { | ||
return $values; | ||
} | ||
|
||
return $this->loadChoiceList($value)->getChoicesForValues($values); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function loadValuesForChoices(array $choices, $value = null) | ||
{ | ||
// Optimize | ||
$choices = array_filter($choices); | ||
if (empty($choices)) { | ||
return array(); | ||
} | ||
|
||
// If no callable is set, choices are the same as values | ||
if (null === $value) { | ||
return $choices; | ||
} | ||
|
||
return $this->loadChoiceList($value)->getValuesForChoices($choices); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.