简体   繁体   English

Sylius:如何自定义右上角的用户菜单?

[英]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)或者,您可以覆盖自定义树枝模板的块toptop 1行),该模板继承了所提到的模板。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 需要自定义woothemes画布中的顶部菜单,具体取决于用户是否登录,我需要显示一个菜单而不是其他菜单 - Need to customize the top menu in woothemes canvas, depending if the user is logged in or not I need to show 1 menu instead of the other 如何编辑此代码,使其仅在用户登录时更改我主页上的顶部菜单栏而不更改主菜单? - How can I edit this code so that it only changes the Top Menu bar on my homepage when a user is logged in without changing the Main Menu? 如何在不修改供应商的情况下自定义 sylius_taxon_image_widget? - How to customize sylius_taxon_image_widget without modifying the vendor? 将右箭头添加到菜单栏 - Add right arrow to menu bar magento中的顶级菜单栏问题 - Top menu bar issue in magento 当商店用户在Sylius进行电子邮件确认时,如何收听事件? - How to listen to the event when a shop user is doing email confirmation at Sylius? 如何覆盖 sylius shop api 插件上的用户注册 - How to overide the user registration on the sylius shop api plugin 如何从magento顶部菜单删除类别而不从侧栏删除 - How to remove categories from magento top menu without removing from side bar 如何将登录用户的个人资料图片添加到我的 wordpress 站点上的 wordpress 顶部栏/菜单栏? - How do I add a logged-in users profile pic to the wordpress top-bar/menu-bar on my wordpress site? 如何在Sylius中上传图片 - How Upload image in Sylius
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM