8000 [Form] improve deprecation messages for the "empty_value" and "choice… · symfony/symfony@72453a7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 72453a7

Browse files
author
Hugo Hamon
committed
[Form] improve deprecation messages for the "empty_value" and "choice_list" options in the ChoiceType class.
1 parent 1230eab commit 72453a7

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,11 @@ public function configureOptions(OptionsResolver $resolver)
292292
return;
293293
};
294294

295-
$choiceListNormalizer = function (Options $options, $choiceList) use ($choiceListFactory) {
295+
// Hack to use the $this variable inside a Closure with PHP 5.3.
296+
$that = $this;
297+
$choiceListNormalizer = function (Options $options, $choiceList) use ($choiceListFactory, $that) {
296298
if ($choiceList) {
297-
@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);
299+
@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);
298300

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

324-
$placeholderNormalizer = function (Options $options, $placeholder) {
326+
// See $that = $this; statement above for the "choice_list" option deprecation.
327+
// It allows to use the $this variable inside a Closure with PHP 5.3.
328+
$placeholderNormalizer = function (Options $options, $placeholder) use ($that) {
325329
if (!is_object($options['empty_value']) || !$options['empty_value'] instanceof \Exception) {
326-
@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);
330+
@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);
327331

328332
$placeholder = $options['empty_value'];
329333
}

0 commit comments

Comments
 (0)
0