EasyAdminBundle
EasyAdminBundle copied to clipboard
User Crud + Enum as Roles -> no default selections in Detail Crud
Describe the bug When you move over to Enums for Roles for Users, then you are free to configure the Crud properly like so:
yield ChoiceField::new('roles', t('Roles'))
->setColumns('col-sm-12 col-md-3')
->setFormTypeOptions([
'choices' => RoleTypesEnum::cases(),
'choice_label' => function (RoleTypesEnum $choice, $key, $value) {
return $choice->value;
},
])
->formatValue(function ($value, $entity) {
return implode(
', ',
array_map(fn(string $r): string => $this->translator->trans(RoleTypesEnum::getByCaseName($r)->value),
$entity->getRoles())
);
})
->renderAsBadges()
->setHelp(t('Employee role cannot be removed.'))
->allowMultipleChoices();
However, this leads to an empty selection field in the Detail overview.
Expectation
The Select Field contains all selected Enum Options automatically, like it would with a non-modified array approach.