-
-
Notifications
You must be signed in to change notification settings - Fork 364
[Autocomplete] Fix bug of not using choice_value #1328
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 |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
use Doctrine\ORM\EntityRepository; | ||
use Doctrine\ORM\QueryBuilder; | ||
use Symfony\Bundle\SecurityBundle\Security; | ||
use Symfony\Component\Form\ChoiceList\Factory\Cache\ChoiceLabel; | ||
use Symfony\Component\Form\ChoiceList\Factory\Cache; | ||
use Symfony\Component\Form\FormFactoryInterface; | ||
use Symfony\Component\Form\FormInterface; | ||
use Symfony\Component\PropertyAccess\PropertyAccessorInterface; | ||
|
@@ -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) { | ||
$choiceLabel = $choiceLabel->getOption(); | ||
} | ||
|
||
|
@@ -99,7 +99,17 @@ public function getLabel(object $entity): string | |
|
||
public function getValue(object $entity): string | ||
{ | ||
return $this->getEntityMetadata()->getIdValue($entity); | ||
$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 commentThe 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 commentThe 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
But there is no problem because is always cast to string.
|
||
} | ||
|
||
if ($choiceValue instanceof Cache\ChoiceValue) { | ||
$choiceValue = $choiceValue->getOption(); | ||
} | ||
|
||
return $choiceValue($entity); | ||
} | ||
|
||
public function isGranted(Security $security): bool | ||
|
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
Uh oh!
There was an error while loading. Please reload this page.
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.
Used in https://github.com/symfony/symfony/blob/7.1/src/Symfony/Component/Form/ChoiceList/Factory/CachingFactoryDecorator.php.
I have no personal opinion, whatever ;)