Admin Sonata 左侧栏中元素的自定义顺序

Custom order for elements on Admin Sonata left sidebar

我正在尝试让左侧具有自定义顺序(不是字母顺序)。我有更多捆绑包,每个捆绑包都有一个自定义 services.yml。在每个 .yml 中,我都有我想要的顺序,但 Sonata 为每个组定制了一个顺序 (A-Z)。如何给出当前索引顺序?我不想将所有代码都放入 app/config/services.yml

imports:
    - { resource: parameters.yml }
    - { resource: security.yml }
    - { resource: services.yml }
    - { resource: currencies.yml }
    - { resource: '@XYZBundle/Resources/config/services.yml' }

XYZBundle/Resource/config/services.yml内容:

services:
    xyz.admin.entity.one:
        class: XYZBundle\Admin\EntityAdmin_1
        arguments: [~, XYZBundle\Entity\Entity_1,  AppBundle:CRUD]
        tags:
            -
                name: sonata.admin
                manager_type: orm
                label:  Entity One
                audit: true
        public: true
    xyz.admin.entity.two:
        class: XYZBundle\Admin\EntityAdmin_2
        arguments: [~, XYZBundle\Entity\Entity_2,  AppBundle:CRUD]
        tags:
            -
                name: sonata.admin
                manager_type: orm
                label:  Entity Two
                audit: true
        public: true
    xyz.admin.entity.three:
        class: XYZBundle\Admin\EntityAdmin_3
        arguments: [~, XYZBundle\Entity\Entity_3,  AppBundle:CRUD]
        tags:
            -
                name: sonata.admin
                manager_type: orm
                label:  Entity Three
                audit: true
        public: true

app/config/config.yml

sonata_admin:
    dashboard:
       groups:
          loan.admin:
              label: Custom XYZ
              icon: '<i class="fa fa-dollar"></i>'
              items:
                  - xyz.admin.entity.one
                  - xyz.admin.entity.two
                  - xyz.admin.entity.three

这是它的样子。 (机密实体名称)

sonata_admin:
    templates:
        # default global templates
        layout:  SonataAdminBundle::layout.html.twig
    title_logo: images/logo.png
    title: Your title
    dashboard:
        groups:
            identifier.for.this.group:
                label:           Your Label
                icon:            '<i class="fa fa-globe"></i>'
                items:
                    - sonata.admin.service_name

奏鸣曲标准服务

sonata.admin.service_name:
    class: AppBundle\Admin\YourSonataAdminClass
    tags:
        - { name: sonata.admin, manager_type: orm, label: "Your Label" }
    arguments:
        - ~
        - AppBundle\Entity\AsociatedEntity
        - ~

我已经这样订购了我的菜单组:

->首先,你应该有一个易于记忆的特定组名(dashboard,bill,......)并在config/services.yaml[=中进行配置35=]:

....
    App\Admin\OrderAdmin:
        arguments: [~, App\Entity\Order, App\Controller\ActionAdminController]
        tags:
            - { name: sonata.admin, manager_type: orm, group: dashboard, label: Orders }
    App\Admin\RequestAdmin:
        arguments: [~, App\Entity\Request, App\Controller\ActionAdminController]
        tags:
            - { name: sonata.admin, manager_type: orm, group: dashboard,label: Request }
    App\Admin\clientAdmin:
        arguments: [~, App\Entity\Client,  App\Controller\ActionAdminController]
        tags:
            - { name: sonata.admin, manager_type: orm, group: dashboard,label: "client" }
    App\Admin\BillAdmin:
        arguments: [~, App\Entity\Bill, App\Controller\ActionAdminController]
        tags:
            - { name: sonata.admin, manager_type: orm, group: bill, label: 'Bill clients' }
        public: true
    App\Admin\DailyBillAdmin:
        arguments: [~, App\Entity\DailyBill, App\Controller\ActionAdminController]
        tags:
            - { name: sonata.admin, manager_type: orm, group: bill, label: 'Daily Bills' }
    App\Admin\OlderBillAdmin:
        arguments: [~, App\Entity\OlderBill, App\Controller\ActionAdminController]
        tags:
            - { name: sonata.admin, manager_type: orm, group: bill, label: 'Older Bills clients' }
        public: true
    App\Admin\ConfigurationAdmin:
        arguments: [~, App\Entity\Configuration, ~]
        tags:
            - { name: sonata.admin, manager_type: orm,group: configuration, label: 'Configuration Taxes' }
    App\Admin\UserAdmin:
        arguments: [~, App\Entity\User, App\Controller\ActionAdminController]
        tags:
            - { name: sonata.admin, manager_type: orm,group: users, label: 'User Management' }
.....

然后您可以在 config/packages/sonata_admin.yaml 中像这样轻松地订购您的群组名称,例如:

sonata_admin:
    title: 'Your Title'
    dashboard:
        blocks:
            - { type: sonata.admin.block.admin_list, position: left }
        groups:
            dashboard:
                label: DASHBOARD
            bill:
                label: BILLS
            configuration:
                label: CONFIGURATIONs
            users:
                label: USERS
            ......

如果您想将项目重新排序到组中或不进入组,您可以使用项目选项。这是相关文档:documentation