在breadcrumb上的奏鸣曲管理员标签

问题描述 投票:6回答:2

我对Symfony的sonata管理员有一点问题。 我想更改breadcrumb中的默认管理标签:

enter image description here

但我找不到任何解决方案。有人能帮我吗?

我找到了这个功能,但它不起作用。看起来这个函数没有被调用。

public function buildBreadcrumbs($action, MenuItemInterface $menu = null) {
    $breadCrumb =  parent::buildBreadcrumbs($action, $menu);

    return $breadCrumb;
}

我使用Symfony 2.8。

symfony sonata-admin breadcrumbs
2个回答
10
投票

尝试覆盖管理类中的classNameLabel属性

// in your ProductAdmin class
public function configure()
{
    parent::configure();
    $this->classnameLabel = "Products";
}

0
投票

实现您想要的最简单方法是更改​​翻译消息。

如果您真的想要更改标签,可以实施自己的标签生成策略。

namespace Blast\CoreBundle\Translator;

use Sonata\AdminBundle\Translator\LabelTranslatorStrategyInterface;

/**
 * Class LibrinfoLabelTranslatorStrategy.
 *
 * Provides a specific label translation strategy for Librinfo.
 * It is based on UnderscoreLabelTranslatorStrategy, but without the context,
 * and labels are prefixed by "librinfo.label."
 *
 * i.e. isValid => librinfo.label.is_valid
 */
class LibrinfoLabelTranslatorStrategy implements LabelTranslatorStrategyInterface
{
    /**
     * {@inheritdoc}
     */
    public function getLabel($label, $context = '', $type = '')
    {
        $label = str_replace('.', '_', $label);

        return sprintf('%s.%s.%s', "librinfo", $type, strtolower(preg_replace('~(?<=\\w)([A-Z])~', '_$1', $label)));
    }
}

将其定义为服务

blast_core.label.strategy.librinfo:
        class: Blast\CoreBundle\Translator\LibrinfoLabelTranslatorStrategy

然后将其传递给管理服务的定义,如下所示:

crm.organism:
        class: Librinfo\CRMBundle\Admin\OrganismAdmin
        arguments: [~, Librinfo\CRMBundle\Entity\Organism, LibrinfoCRMBundle:OrganismAdmin]
        tags:
            -   name: sonata.admin
                manager_type: orm
                group: Customers Relationship Management
                label_translator_strategy: blast_core.label.strategy.librinfo

您可以完全控制管理员标签

另见:SonataAdmin: replace ID in breadcrumbs

© www.soinside.com 2019 - 2024. All rights reserved.