[英]SonataAdmin, Add a item to the side menu
I am trying to add the items/route to the side menu, basically I have User which has list and add functionality listed in dashboard, now I would like to have these under my sidebar menu too. 我正在尝试将项目/路线添加到侧边菜单,基本上我在面板中列出了具有列表和添加功能的用户,现在我也想在侧边栏菜单下添加这些功能。
I registered a service: 我注册了服务:
#config/services.yml
admin.user:
class: AdminBundle\Admin\UserAdmin
arguments: [~, AppBundle\Entity\User, AdminBundle:UserAdmin]
tags:
- { name: sonata.admin, manager_type: orm, group: admin, label: User }
calls:
- [ setAuthorizationChecker, ['@security.authorization_checker']]
Followed by configuration for dashboard. 接下来是仪表盘的配置。
sonata_admin:
templates:
dashboard: 'SonataAdminBundle:Core:dashboard.html.twig'
layout: 'AdminBundle::standard_layout.html.twig'
user_block: 'AdminBundle:Core:user_block.html.twig'
title: 'Book-a-slot<br /><span>Admin panel</span>'
title_logo: bundles/app/images/logo.png
dashboard:
groups:
user:
label: User
items:
- admin.user
blocks:
-
position: left
type: sonata.admin.block.admin_list
Looked into configureTabMenu if I can add through it but no luck. 查看configureTabMenu,如果我可以添加它,但没有运气。
protected function configureTabMenu(MenuItemInterface $menu, $action, AdminInterface $childAdmin = null)
{
if (!$childAdmin && !in_array($action, ['edit', 'show'])) {
return;
}
$menu->addChild(
'User Create',
[
'uri' => $this->generateUrl(UserAdmin::class.'.create'),
]
);
}
Items in Dashboard 仪表板中的项目
You can check the name of your routes by doing php bin/console debug:router. 您可以通过执行php bin / console debug:router来检查路由的名称。 But, I suppose it's.
但是,我想是。
So what's next? 下一个是什么? You must register menuBuilderListener.
您必须注册menuBuilderListener。 (We will hook into process of menu creation and there you will have full control)
(我们将进入菜单创建过程,在那里您将拥有完全控制权)
Services.yml Services.yml
app.menu_admin:
class: AdminBundle\EventListener\MenuBuilderListener
tags:
- { name: kernel.event_listener, event: sonata.admin.event.configure.menu.sidebar, method: adminMenuItems }
Next create folder for EventListeners and create MenuBuilderListener there. 接下来为EventListeners创建文件夹,并在其中创建MenuBuilderListener。 I will just copy paste one of my listeners, I have used recently.
我将只复制粘贴我最近使用过的一个听众。 (adjust to your needs).
(根据您的需要进行调整)。
<?php
namespace AdminBundle\EventListener;
use Sonata\AdminBundle\Event\ConfigureMenuEvent;
/**
* Class MenuBuilderListener
* @package AdminBundle\EventListener
*/
class MenuBuilderListener
{
/**
* @param ConfigureMenuEvent $event
*/
public function adminMenuItems(ConfigureMenuEvent $event)
{
$event->getMenu()
->addChild(
'dashboard',
[
'route' => 'admin_dashboard',
]
)
->setExtras(
[
'icon' => '<span class="menu-ico mif mif-chart-pie"></span> ',
]
)
->setLabel('Dashboard')
->getParent()
->addChild(
'reviews',
[
'route' => 'admin_reviews',
]
)
->setExtras(
[
'icon' => '<span class="mif mif-bubble"></span> ',
]
)
->setLabel('Reviews')
->getParent()
->addChild('pages')
->setExtras(
[
'icon' => '<span class="mif mif-files-empty"></span> ',
]
)
->setLabel('Pages')
->addChild('home', ['route' => 'admin_pages_home'])
->setExtras(
[
'icon' => '<span class="mif mif-file-empty"></span> ',
]
)
->setLabel('Home')
->getParent()
->addChild('review', ['route' => 'admin_pages_review'])
->setExtras(
[
'icon' => '<span class="mif mif-file-empty"></span> ',
]
)
->setLabel('Review')
->getParent()
->addChild('about_us', ['route' => 'admin_pages_about_us'])
->setExtras(
[
'icon' => '<span class="mif mif-file-empty"></span> ',
]
)
->setLabel('About Us')
->getParent()
->getParent();
}
}
That's all. 就这样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.