[英]Sylius: how to customize to User-menu in top right bar?
As described in the official Docs , i was able to customize both the Admin-Dashboard menu and also the Menu in the account section for a user. 如官方文档中所述,我能够为用户自定义Admin-Dashboard菜单和帐户部分中的Menu。
However, how can i customize the menu, that is shown in upper top right bar including menu items like " My account " and " Logout "? 但是,我如何自定义菜单,该菜单显示在右上角的菜单栏中,其中包括“ 我的帐户 ”和“ 注销 ”之类的菜单项? I want to add some items here. 我想在这里添加一些项目。
This is what i mean: 这就是我的意思:
What i have done so far: 到目前为止,我所做的是:
First i have defined the MenuBuilder-Customization in services.yml: 首先,我在services.yml中定义了MenuBuilder-Customization:
app.listener.shop.menu_builder:
class: AppBundle\Menu\AccountMenuListener
tags:
- { name: kernel.event_listener, event: sylius.menu.shop.account, method: addAccountMenuItems }
- { name: kernel.event_listener, event: sylius.shop.menu_builder.account, method: addTopMenuMenuItems }
- { name: kernel.event_listener, event: sylius.menu_builder.frontend.main, method: addTopMenuMenuItems }
And this is my customized MenuBuilder: 这是我自定义的MenuBuilder:
<?php
namespace AppBundle\Menu;
use Knp\Menu\MenuItem;
use Sylius\Bundle\UiBundle\Menu\Event\MenuBuilderEvent;
final class AccountMenuListener
{
/**
* @param MenuBuilderEvent $event
*/
public function addAccountMenuItems(MenuBuilderEvent $event): void
{
$menu = $event->getMenu();
$menu->removeChild('address_book');
$menu->removeChild('order_history');
$menu
->addChild('new', ['route' => 'sylius_shop_homepage'])
->setLabel('My Reservations')
->setLabelAttribute('icon', 'star');
}
public function addTopMenuMenuItems(MenuBuilderEvent $event): void
{
$menu = $event->getMenu();
// list all items
foreach($menu->getChildren() as $child) {
echo $child->getName() . '<br>';
}
die;
}
}
At least for the Side-Menu that appears in "my account" section, everything worked well. 至少对于“我的帐户”部分中显示的侧面菜单,一切正常。 But the top-right-menu can't get reached this way. 但是无法通过这种方式到达右上菜单。 Whether "sylius.menu_builder.frontend.main" nor "sylius.shop.menu_builder.account" will catch here. 无论是“ sylius.menu_builder.frontend.main”还是“ sylius.shop.menu_builder.account”都可以在这里找到。
How can it be done properly? 如何正确完成?
There are two ways: 有两种方法:
1) you should override these lines: https://github.com/Sylius/Sylius/blob/1.2/src/Sylius/Bundle/ShopBundle/Resources/views/layout.html.twig#L33 . 1)您应该覆盖这些行: https : //github.com/Sylius/Sylius/blob/1.2/src/Sylius/Bundle/ShopBundle/Resources/views/layout.html.twig#L33 。
2) Or you can override block top
(1 line above) inyour custom twig template, which inherits that mentioned template. 2)或者,您可以覆盖自定义树枝模板的块top
( top
1行),该模板继承了所提到的模板。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.