Skip to content

Commit

Permalink
[Form] improve deprecation messages for the "empty_value" and "choice…
Browse files Browse the repository at this point in the history
…_list" options in the ChoiceType class.
  • Loading branch information
Hugo Hamon committed Dec 24, 2015
1 parent 1230eab commit 72453a7
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,11 @@ public function configureOptions(OptionsResolver $resolver)
return;
};

$choiceListNormalizer = function (Options $options, $choiceList) use ($choiceListFactory) {
// Hack to use the $this variable inside a Closure with PHP 5.3.
$that = $this;
$choiceListNormalizer = function (Options $options, $choiceList) use ($choiceListFactory, $that) {
if ($choiceList) {
@trigger_error('The "choice_list" option is deprecated since version 2.7 and will be removed in 3.0. Use "choice_loader" instead.', E_USER_DEPRECATED);
@trigger_error(sprintf('The "choice_list" option of "%s" (%s) is deprecated since version 2.7 and will be removed in 3.0. Use "choice_loader" instead.', $that->getName(), __CLASS__), E_USER_DEPRECATED);

if ($choiceList instanceof LegacyChoiceListInterface) {
return new LegacyChoiceListAdapter($choiceList);
Expand All @@ -321,9 +323,11 @@ public function configureOptions(OptionsResolver $resolver)
return $choiceListFactory->createListFromChoices($choices, $options['choice_value']);
};

$placeholderNormalizer = function (Options $options, $placeholder) {
// See $that = $this; statement above for the "choice_list" option deprecation.
// It allows to use the $this variable inside a Closure with PHP 5.3.
$placeholderNormalizer = function (Options $options, $placeholder) use ($that) {
if (!is_object($options['empty_value']) || !$options['empty_value'] instanceof \Exception) {
@trigger_error('The form option "empty_value" is deprecated since version 2.6 and will be removed in 3.0. Use "placeholder" instead.', E_USER_DEPRECATED);
@trigger_error(sprintf('The form option "empty_value" of "%s" (%s) is deprecated since version 2.6 and will be removed in 3.0. Use "placeholder" instead.', $that->getName(), __CLASS__), E_USER_DEPRECATED);

$placeholder = $options['empty_value'];
}
Expand Down

0 comments on commit 72453a7

Please sign in to comment.