From b1f71cbf6019d98d1a4350b135d49b95d43656db Mon Sep 17 00:00:00 2001
From: Dmitry Chernikov <4ernikoff@gmail.com>
Date: Tue, 17 Jun 2014 20:02:12 +0300
Subject: [PATCH] `yii\widgets\Breadcrumbs` enhancement. Allow link to have its
`ownTemplate`
---
framework/widgets/Breadcrumbs.php | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/framework/widgets/Breadcrumbs.php b/framework/widgets/Breadcrumbs.php
index f359927d86..8179500186 100644
--- a/framework/widgets/Breadcrumbs.php
+++ b/framework/widgets/Breadcrumbs.php
@@ -24,7 +24,13 @@ use yii\helpers\Html;
* ~~~
* // $this is the view object currently being used
* echo Breadcrumbs::widget([
+ * 'itemTemplate' => "
{link}\n", // template for all links
* 'links' => [
+ * [
+ * 'label' => 'Post Category',
+ * 'url' => ['post-category/view', 'id' => 10],
+ * 'ownTemplate' => '{link}\n', // template for this link only
+ * ],
* ['label' => 'Sample Post', 'url' => ['post/edit', 'id' => 1]],
* 'Edit',
* ],
@@ -76,6 +82,7 @@ class Breadcrumbs extends Widget
* [
* 'label' => 'label of the link', // required
* 'url' => 'url of the link', // optional, will be processed by Url::to()
+ * 'ownTemplate' => 'own template of the current item', // optional, if not set $this->itemTemplate will be used
* ]
* ~~~
*
@@ -135,9 +142,9 @@ class Breadcrumbs extends Widget
throw new InvalidConfigException('The "label" element is required for each link.');
}
if (isset($link['url'])) {
- return strtr($template, ['{link}' => Html::a($label, $link['url'])]);
+ return strtr(isset($link['ownTemplate']) ? $link['ownTemplate'] : $template, ['{link}' => Html::a($label, $link['url'])]);
} else {
- return strtr($template, ['{link}' => $label]);
+ return strtr(isset($link['ownTemplate']) ? $link['ownTemplate'] : $template, ['{link}' => $label]);
}
}
}