Search code examples
symfonysymfony4easyadmin

Can't edit the roles of the users in the easyAdminBundle .yml symfony


easy_admin:
entities:
    User:
        class: App\Entity\User
        disabled_actions: ['new']
        avatar_property_path: 'picture'
        form:
            fields:
                - {property: 'rank'}
                - { property: 'roles',
                    type: choice,type_options: { mapped: true, expanded: true, multiple: true},
                    choices: [role_admin: 'ROLE_ADMIN' , role_user: 'ROLE_USER'] }

this is the code that i wrote and this is the result :

enter image description here


Solution

  • you should do like this instead of form

    easy_admin:
    entities:
        User:
            class: App\Entity\User
            disabled_actions: ['new']
            avatar_property_path: 'picture'
            new:
                fields:
                    - {property: 'rank'}
                    - { property: 'roles',
                        type: choice,type_options: { mapped: true, expanded: true, multiple: true},
                        choices: [role_admin: 'ROLE_ADMIN' , role_user: 'ROLE_USER'] }
            edit:
                    fields:
                        - {property: 'rank'}
                        - { property: 'roles',
                            type: choice,type_options: { mapped: true, expanded: true, multiple: true},
                            choices: [role_admin: 'ROLE_ADMIN' , role_user: 'ROLE_USER'] }