我想像树一样嵌套菜单项。我现在有这个配置:
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 的推荐,我通过扩展菜单进行了一些更改,因此我在下面创建了一个文件PDI\PDOneBundle\EventListener\MenuBuilderListener.php
,如下所示:
namespace PDI\PDOneBundle\EventListener;
use Sonata\AdminBundle\Event\ConfigureMenuEvent;
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();
}
}
然后我注册监听器PDI\PDOneBundle\Resources\config\services.yml
如下:
services:
app.menu_listener:
class: PDI\PDOneBundle\EventListener\MenuBuilderListener
tags:
- { name: kernel.event_listener, event: sonata.admin.event.configure.menu.sidebar, method: createMainMenu }
但由于仍显示相同的默认菜单,因此无法正常工作。有什么建议吗?