6. Roles Matrix

The Sonata\UserBundle\Form\Type\RolesMatrixType was built to show all roles in a matrix view.

Role matrix

Every admin has defined default roles like:

  • EDIT

  • LIST


  • VIEW



  • ALL

The roles matrix consists of two parts:

  1. one that shows the matrix with each admin and their permissions.

  2. another that shows the custom roles which are configured in config/packages/security.yaml and lists them as checkboxes (and shows their inherited roles).


The user can just use roles which he is granted.

6.1. How to exclude an admin

You can set the show_in_roles_matrix option to false, like this:

# config/services.yaml

        class: App\Admin\PostAdmin
                name: sonata.admin
                model_class: App\Entity\Post
                manager_type: orm
                label: 'Post'
                show_in_roles_matrix: false

6.2. How to exclude roles

When using the Form Type, you can use excluded_roles to not show them in the matrix. By default, only UserInterface::ROLE_DEFAULT aka ROLE_USER is not shown.