Describe the bug
easycorp/easyadmin-bundle v3.0.2
I'm using the ChoiceField field as in the description, but I get an error.
To Reproduce
UserCrudController.php:
public function configureFields(string $pageName): iterable
{
return [
ChoiceField::new('roles')->setChoices(['ROLE_ADMIN' => 'ROLE_ADMIN']),
];
}
Notice: Array to string conversion
(OPTIONAL) Additional context
In my User entity:
/**
* @ORM\Column(type="json")
*/
private $roles = [];
Can you try ->allowMultipleChoices() on the field? That should set the multiple option, and therefore allow it to handle array values.
@lukasluecke it worked, thanks :)
could this not be done automatically?
It probably could be done in the ChoiceConfigurator - however I'm hesistant to add more metadata-specific logic there until #3389 is somewhat handled 馃檲
Using a ChoiceField for a JSON Doctrine type can be considered an "edge case" (a CodeEditorField or a future JsonField should be used). So, for now, I'm closing this as "fixed" thanks to @lukasluecke solution. Thanks!
Most helpful comment
Can you try
->allowMultipleChoices()on the field? That should set themultipleoption, and therefore allow it to handle array values.