-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] handle callable strings in PropertyAccessDecorator #18057
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -172,6 +172,11 @@ public function createView(ChoiceListInterface $list, $preferredChoices = null, | |
|
||
if (is_string($label) && !is_callable($label)) { | ||
$label = new PropertyPath($label); | ||
} elseif (is_string($label) && is_callable($label)) { | ||
// Prevent a fatal error since a callable string may not handle the right arguments | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How does it prevent a fatal error ? You call it with the same argument There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @stof Actually |
||
$label = function ($choice) use ($label) { | ||
return $label($choice); | ||
}; | ||
} | ||
|
||
if ($label instanceof PropertyPath) { | ||
|
@@ -182,6 +187,11 @@ public function createView(ChoiceListInterface $list, $preferredChoices = null, | |
|
||
if (is_string($preferredChoices) && !is_callable($preferredChoices)) { | ||
$preferredChoices = new PropertyPath($preferredChoices); | ||
} elseif (is_string($preferredChoices) && is_callable($preferredChoices)) { | ||
// Prevent a fatal error since a callable string may not handle the right arguments | ||
$preferredChoices = function ($choice) use ($preferredChoices) { | ||
return $preferredChoices($choice); | ||
}; | ||
} | ||
|
||
if ($preferredChoices instanceof PropertyPath) { | ||
|
@@ -197,6 +207,11 @@ public function createView(ChoiceListInterface $list, $preferredChoices = null, | |
|
||
if (is_string($index) && !is_callable($index)) { | ||
$index = new PropertyPath($index); | ||
} elseif (is_string($index) && is_callable($index)) { | ||
// Prevent a fatal error since a callable string may not handle the right arguments | ||
$index = function ($choice) use ($index) { | ||
return $index($choice); | ||
}; | ||
} | ||
|
||
if ($index instanceof PropertyPath) { | ||
|
@@ -207,6 +222,11 @@ public function createView(ChoiceListInterface $list, $preferredChoices = null, | |
|
||
if (is_string($groupBy) && !is_callable($groupBy)) { | ||
$groupBy = new PropertyPath($groupBy); | ||
} elseif (is_string($groupBy) && is_callable($groupBy)) { | ||
// Prevent a fatal error since a callable string may not handle the right arguments | ||
$groupBy = function ($choice) use ($groupBy) { | ||
return $groupBy($choice); | ||
}; | ||
} | ||
|
||
if ($groupBy instanceof PropertyPath) { | ||
|
@@ -221,6 +241,11 @@ public function createView(ChoiceListInterface $list, $preferredChoices = null, | |
|
||
if (is_string($attr) && !is_callable($attr)) { | ||
$attr = new PropertyPath($attr); | ||
} elseif (is_string($attr) && is_callable($attr)) { | ||
// Prevent a fatal error since a callable string may not handle the right arguments | ||
$attr = function ($choice) use ($attr) { | ||
return $attr($choice); | ||
}; | ||
} | ||
|
||
if ($attr instanceof PropertyPath) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this should be the responsibility of the
DefaultChoiceListFactory
as the interface is supposed to supportcallable
anyway.Then it would just need to make
PropertyAccessDecorator
treat callable strings as strings, instead of passing them to the decorated factory as it is.But one using the
DefaultChoiceListFactory
without decorator should not experience this bug.What do you think @webmozart ?