how to create custom list with sonata admin

為{幸葍}努か 提交于 2019-12-24 09:25:06

问题


I can't find (understand) how to add items and cathegories to Left Side Admin Menu. There is no detailed tutorial how to do this. I can add items to sonata.admin.block.admin_list but to aside Admin Menu enter image description here


回答1:


Since the menu is automatically built by traversing the registered admins there is no (to me known) simple solution for that by adding just an admin service entry. But it's quite easy yet. You could register a MenuBuilderListener and add new items as many as you want ...

In your services.yml

app.menu_listener:
    class: AppBundle\Listener\MenuBuilderListener
    tags:
        - { name: kernel.event_listener, event: sonata.admin.event.configure.menu.sidebar, method: addMenuItems }

In you MenuBuilderListener class

public function addMenuItems(ConfigureMenuEvent $event)
{
    $event->getMenu()->addChild($event->getFactory()->createItem('Test entry', ['route' => 'custom_route']));
    ...
}

The event is called after your menu is build ... you can change existing menu entries afterwards or just add new entries. Note that the admin service usually will take responsibility for creating routes, if you don't have an admin you have to build routes by yourself.




回答2:


Yes you can do sth like that:

sonata_admin:
title:      Supplier Portal
title_logo: bundles/supplierportalbackend/img/logo.png
show_mosaic_button: false
security:
    handler: sonata.admin.security.handler.role
templates:
    layout:              SonataAdminBundle::layout.html.twig
    search:              SonataAdminBundle:Core:search.html.twig
    search_result_block: SonataAdminBundle:Block:block_search_result.html.twig
    base_list_field:     SonataAdminBundle:CRUD:base_list_field.html.twig

dashboard:
    blocks:
        - { position: left, type: sonata.admin.block.admin_list }
    # Customize user portal menu by setting links
    groups:
        sonata.admin.group.purchase_order_item.open:
            on_top:          true
            label:           Open Items
            label_catalogue: messages
            icon:            '<i class="fa fa-square-o"></i>'
            items:
                - supplier_portal_backend.admin.purchase_open_order_item

        sonata.admin.group.purchase_order_item.confirmed:
            on_top:          true
            label:           Confirmed Items
            label_catalogue: messages
            icon:            '<i class="fa fa-check-square-o"></i>'
            items:
                - supplier_portal_backend.admin.purchase_confirmed_order_item

        sonata.admin.group.purchase_order_item.shipped:
            on_top:          true
            label:           Shipped Items
            label_catalogue: messages
            icon:            '<i class="fa fa-truck"></i>'
            items:
                - supplier_portal_backend.admin.purchase_shipped_order_item

        sonata.admin.group.purchase_order_item.all:
            on_top:          true
            label:           All Items
            label_catalogue: messages
            icon:            '<i class="fa fa-th-list"></i>'
            items:
                - supplier_portal_backend.admin.purchase_order_item

        sonata.admin.group.administration:
            on_top:          true
            label:           Users
            label_catalogue: messages
            icon:            '<i class="fa fa-users"></i>'
            items:
                - supplier_portal_backend.admin.user
            roles: [ ROLE_SUPER_ADMIN ]



回答3:


You need to add a route to your routing:

admin.blog_post:
    class: db306\CoreBundle\Admin\BlogPostAdmin
    arguments: [~, db306\CoreBundle\Entity\BlogPost, ~]
    tags:
        - { name: sonata.admin, manager_type: orm, group: Content, label: Blog post }
    public: true

admin.category:
    class: db306\CoreBundle\Admin\CategoryAdmin
    arguments: [~, db306\CoreBundle\Entity\Category, ~]
    tags:
        - { name: sonata.admin, manager_type: orm, group: Content, label: Category }
    public: true

This will display a "Content" tab on that menu displayed on your screenshot with 2 options: 'Blog post' and 'Category'



来源:https://stackoverflow.com/questions/47274367/how-to-create-custom-list-with-sonata-admin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!