Search code examples
symfonysonata-adminsonata

Change left menu labels on Sonata Admin


How can I change the labels in the left menu of my Sonata Admin installation?

I would like to change (and understand how they are generated):

  1. The "admin" text
  2. The "PostCategory" label (and change it to something more "WordPress-ish" :) like "Post Categories")

enter image description here


Solution

  • These labels are defined in the tags property in the service definition of your admin page, in the config file of the admin section. See documentation here.

    Example in a admin-services.yml file:

    services:
      app.admin.category:
        class: AppBundle\Admin\CategoryAdmin
        tags:
          - { name: sonata.admin, manager_type: orm, group: "My Admin Group", label: "Post Categories" }
        arguments:
          - ~
          - AppBundle\Entity\Category
          - ~
        calls:
          - [ setTranslationDomain, [AppBundle]]
    

    The group tag corresponds to your admin label, and the label one to your PostCategory.

    I guess you didn't specify these tags, and admin is the default group name, and PostCategory the name of your class.

    EDIT:

    The label and the group option are translation keys. You specify the translation domain under the calls tag, with setTranslationDomain, and the default catalog is messages. See documentation on translation here.