Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add choice_translation_locale option for Intl choice types
- Loading branch information
Showing
12 changed files
with
379 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
UPGRADE FROM 4.1 to 4.2 | ||
======================= | ||
|
||
Form | ||
---- | ||
|
||
* Deprecated the `ChoiceLoaderInterface` implementation in `CountryType`, `LanguageType`, `LocaleType` and `CurrencyType`, use the `choice_loader` option instead. | ||
|
||
Before: | ||
```php | ||
class MyCountryType extends CountryType | ||
{ | ||
public function loadChoiceList() | ||
{ | ||
// override the method | ||
} | ||
} | ||
``` | ||
|
||
After: | ||
```php | ||
class MyCountryType extends AbstractType | ||
{ | ||
public function getParent() | ||
{ | ||
return CountryType::class; | ||
} | ||
|
||
public function configureOptions(OptionsResolver $resolver) | ||
{ | ||
$resolver->setDefault('choice_loader', ...); // override the option instead | ||
} | ||
} | ||
``` |
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.