-
-
Notifications
You must be signed in to change notification settings - Fork 340
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
[Autocomplete] Fix bug of not using choice_value #1328
Conversation
It could be simpler for this autocompleter service if it built the form view (i.e., |
@@ -89,7 +89,7 @@ public function getLabel(object $entity): string | |||
return $this->propertyAccessor->getValue($entity, $choiceLabel); | |||
} | |||
|
|||
if ($choiceLabel instanceof ChoiceLabel) { | |||
if ($choiceLabel instanceof Cache\ChoiceLabel) { |
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.
A particular reason for this change ?
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.
To have only one use.
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.
I'm not sure this offers a better readability, but let's see what others think
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.
I'm not sure this offers a better readability, but let's see what others think
Used in https://github.com/symfony/symfony/blob/7.1/src/Symfony/Component/Form/ChoiceList/Factory/CachingFactoryDecorator.php.
I have no personal opinion, whatever ;)
$choiceValue = $this->getFormOption('choice_value'); | ||
|
||
if (\is_string($choiceValue) || $choiceValue instanceof PropertyPathInterface) { | ||
return $this->propertyAccessor->getValue($entity, $choiceValue); |
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.
The return type of the method is not compatible with all the new possibilities no ? Integers, floats, nulls, ...
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.
Historically, there's already a "problem" when we see the return type of getIdentifierValues()
:
/**
* Returns the identifier of this object as an array with field name as key.
*
* Has to return an empty array if no identifier isset.
*
* @return array<string, mixed>
*/
public function getIdentifierValues(object $object);
But there is no problem because is always cast to string.
By default, PHP will coerce values of the wrong type into the expected scalar type declaration if possible. For example, a function that is given an int for a parameter that expects a string will get a variable of type string.
That's a really interesting idea. After all, our goal is to return the text and value that is rendered on the frontend. So creating the form view, then extracting from there makes a lot of sense. @ytilotti would you mind giving that a shot? |
I don't see @yceruto's idea. Maybe he can suggest it? |
Sorry for the delay @ytilotti - it's this idea: #1328 (comment) So instead of getting the $view = $this->getForm()->createView();
return $view->vars['value']; |
The option choice_value (like EntityType) is not used in Autocomplete ux on
AsEntityAutocompleteField
class.