2016-12-22 43 views
4

我已經與索納塔管理一個小問題上的symfony 我會改變麪包屑默認的admin標籤奏鳴曲管理標籤上的麪包屑

enter image description here

,但我沒有找到任何解決辦法,有人能幫助我?

,我發現這個功能,但沒有作品,貌似這個功能是不是叫

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

    return $breadCrumb; 
} 

PS。我使用symfony 2.8 謝謝

+0

如果只是想修改標籤的翻譯,而不是它們的結構,就可以了'SonataAdminBundle :: standard_layout.html內覆蓋'sonata_breadcrumb'塊.twig'模板。爲'label' var放置正確的翻譯域,並在其中翻譯標籤。 –

+0

嗯,我是奏鳴曲的新手,你有沒有例子? –

+0

ps。我不想翻譯「名單」,但「測試產品」 正確breacrumb是 儀表板/產品/產品列表 或 儀表板/產品列表/產品列表 –

回答

8

嘗試重寫classNameLabel財產在你的管理類

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

它的作品,謝謝! –

+1

你不需要在configure方法中有這個,只需將protected var添加到ProductAdmin類的頂部:'protected $ classnameLabel ='Products';' – lopsided

+0

@ AndreaG.Pigliafreddo如果它是正確的爲你。 –

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 

然後將它傳遞給你的管理服務的定義,像這樣:

你將擁有管理員的完全控制標籤

另請參閱:SonataAdmin: replace ID in breadcrumbs

相關問題