我正在尝试将项目/路线添加到侧边菜单,基本上我在仪表板上列出了具有列表和添加功能的用户,现在我也想在侧边栏菜单下添加这些功能。
我注册了服务:
#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']]
随后是仪表板的配置。
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
如果我可以添加它,但没有运气,可以进入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'),
]
);
}
仪表板上的项目
答案 0 :(得分:1)
您可以通过执行php bin / console debug:router来检查路由的名称。但是,我想是。
那接下来呢?您必须注册menuBuilderListener。 (我们将进入菜单创建过程,在那里您将拥有完全控制权)
Services.yml
app.menu_admin:
class: AdminBundle\EventListener\MenuBuilderListener
tags:
- { name: kernel.event_listener, event: sonata.admin.event.configure.menu.sidebar, method: adminMenuItems }
接下来为EventListeners创建文件夹,并在其中创建MenuBuilderListener。我将只复制粘贴我最近使用过的一个听众。 (根据您的需要进行调整。)
<?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();
}
}
仅此而已。