在SonataAdminBundle边栏中嵌套菜单项



我想把菜单项嵌套成树状。我现在有这样的配置:

dashboard:
    groups:
        company:
            icon: <i class="fa fa-lg fa-fw fa fa-cogs"></i>
            label: Company
            items:
                - sonata.admin.company
                - sonata.admin.brand
                - sonata.admin.media
                - sonata.admin.message
        territory:
            icon: <i class="fa fa-lg fa-fw fa fa-cogs"></i>
            label: Territory
            items:
                - sonata.admin.territory
                - sonata.admin.target
        reps:
            icon: <i class="fa fa-lg fa-fw fa fa-cogs"></i>
            label: Representative
            items:
                - sonata.admin.representative
                - sonata.admin.email
                - sonata.admin.targetbrand
                - sonata.admin.territorybrand

我想要这样写:

dashboard:
    groups:
        company:
            icon: <i class="fa fa-lg fa-fw fa fa-cogs"></i>
            label: Company
            label_catalogue: PDOneBundle
            items:
                - sonata.admin.company
                    - sonata.admin.brand
                        - sonata.admin.media
                        - sonata.admin.message
        territory:
            icon: <i class="fa fa-lg fa-fw fa fa-cogs"></i>
            label: Territory
            label_catalogue: PDOneBundle
            items:
                - sonata.admin.territory
                     - sonata.admin.target
        reps:
            icon: <i class="fa fa-lg fa-fw fa fa-cogs"></i>
            label: Representative
            label_catalogue: PDOneBundle
            items:
                - sonata.admin.representative
                    - sonata.admin.email

我怎么能做到呢?这是可能的吗?

基于SonataAdminBundle的文档和推荐的@hugo-briand我通过扩展菜单做了一些更改,所以我在PDIPDOneBundleEventListenerMenuBuilderListener.php下创建了一个文件,看起来像这样:

namespace PDIPDOneBundleEventListener;
use SonataAdminBundleEventConfigureMenuEvent;
class MenuBuilderListener
{
    public function createMainMenu(ConfigureMenuEvent $event)
    {
        $menu = $event->getMenu();
            $menu
                ->addChild('Dashboard', array('uri' => '/'))
                ->setAttribute('icon', 'fa fa-home');
            $menu
                ->addChild('Company', array())
                ->setAttribute('icon', 'fa fa-inbox')
                ->addChild('Company', array(
                   'route' => 'admin_pdi_pdone_company_list',
                ))
                ->setAttribute('icon', 'fa fa-inbox')
                ->getParent()
                ->addChild('Brand', array(
                    'route' => 'admin_pdi_pdone_brand_list',
                ))
                ->setAttribute('icon', 'fa fa-inbox')
                ->addChild('Media', array(
                    'route' => 'admin_pdi_pdone_media_list',
                ))
                ->setAttribute('icon', 'fa fa-inbox')
                ->getParent();
    }
}

然后我在PDIPDOneBundleResourcesconfigservices.yml注册了侦听器,如下所示:

services:
    app.menu_listener:
        class: PDIPDOneBundleEventListenerMenuBuilderListener
        tags:
            - { name: kernel.event_listener, event: sonata.admin.event.configure.menu.sidebar, method: createMainMenu }

但是不工作,因为相同的默认菜单仍然显示。任何建议吗?

可以。但不完全像你指定的那样。

SonataAdmin现在集成了KnpMenu来生成侧菜单。这里有文档(https://sonata-project.org/bundles/admin/master/doc/cookbook/recipe_knp_menu.html);不过请注意使用主版本,这还没有作为稳定版本发布。

注意:由于文档尚未重新发布,因此缺少一些信息。你可以直接在Github仓库上看到它:https://github.com/sonata-project/SonataAdminBundle/blob/41328b42f91bf4c72153cdb1fc2c50a5092c7755/Resources/doc/cookbook/recipe_knp_menu.rst

对于菜单中的每个项目,您现在可以提供一个KnpMenu提供程序来生成您的菜单,并覆盖相关的布局

相关内容

  • 没有找到相关文章

最新更新