我想嵌套菜单项,如树。我现在有这样的配置:
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的docs并由 @ hugo-briand 推荐,我在extending the menu进行了一些更改,因此我在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 }
但由于仍然显示相同的默认菜单,因此无效。有什么建议吗?
答案 0 :(得分:1)
是的,你可以。但不完全像你指定的那样。
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提供程序,并覆盖相关的布局。