EasyAdminBundle icon indicating copy to clipboard operation
EasyAdminBundle copied to clipboard

User Crud + Enum as Roles -> no default selections in Detail Crud

Open bytes-commerce opened this issue 1 year ago • 0 comments

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.

bytes-commerce avatar Oct 26 '23 12:10 bytes-commerce