symfonyeasyadmin

How to edit the Main Menu Labels in Symfony 5, EasyAdmin 4?


I am using Symfony EasyAdmin 4 and couldn't figure out how to change the main menu's entities' labels. They default to their entities' name.

This seems easily achievable with EasyAdmin 2.x, as the old docs show. But none of the files mentioned there (translations/messages.xx.yaml,config/packages/easy_admin.yaml) is still in use in EasyAdmin 4.x.

So, how to edit the Main Menu Labels in EasyAdmin?


Solution

  • We don't need any of those files in EasyAdmin 4:

    This can be achieved by simply implementing setEntityLabelInSingular and setEntityLabelInPlural methods inside the configureCrud method inside the concerned crud controller:

    class YourCrudController extends AbstractCrudController
    {     
        public function configureCrud(Crud $crud): Crud
             {
                 return $crud
                     ->setEntityLabelInSingular('Your own label')
                     ->setEntityLabelInPlural('Your own labels')
                     ...
                     ;
              }
    ...
    }
    

    Don't forget the : use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;


    More here: Symfony: The Fast Track