diff --git a/CHANGELOG.md b/CHANGELOG.md index 2071a64..779db16 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ Yii Framework 2 bootstrap5 extension Change Log 2.0.3 under development ----------------------- +- Enh #24: Accept `Breadcrumbs::$homeLink = false` to omit "Home" link (fetus-hina) - Enh #27: Changed all data- and aria- attributes to short syntax (simialbi) - Enh #26: Add Bootstrap icon asset (Krakozaber) - Enh #18: Add rangeInput(), colorInput() and switch mode to checkbox() in class ActiveField (WinterSilence) diff --git a/src/Breadcrumbs.php b/src/Breadcrumbs.php index 1607f3e..e8bed18 100644 --- a/src/Breadcrumbs.php +++ b/src/Breadcrumbs.php @@ -40,7 +40,7 @@ class Breadcrumbs extends Widget */ public $encodeLabels = true; /** - * @var array the first hyperlink in the breadcrumbs (called home link). + * @var array|bool the first hyperlink in the breadcrumbs (called home link). * Please refer to [[links]] on the format of the link. * If this property is not set, it will default to a link pointing to [[\yii\web\Application::homeUrl]] * with the label 'Home'. If this property is false, the home link will not be rendered. @@ -113,7 +113,7 @@ class Breadcrumbs extends Widget 'label' => 'Home', 'url' => '/', ], $this->itemTemplate); - } else { + } elseif ($this->homeLink !== false) { $links[] = $this->renderItem($this->homeLink, $this->itemTemplate); } @@ -165,11 +165,11 @@ class Breadcrumbs extends Widget * If this property is not set, it will default to a link pointing with the label 'Home'. If this property is false, * the home link will not be rendered. * - * @param array $value + * @param array|bool $value * * @return $this */ - public function homeLink(array $value): self + public function homeLink($value): self { $this->homeLink = $value; @@ -295,5 +295,4 @@ class Breadcrumbs extends Widget return strtr($template, ['{link}' => $linkHtml]); } - } diff --git a/tests/BreadcrumbsTest.php b/tests/BreadcrumbsTest.php index 8c32444..4d561a4 100644 --- a/tests/BreadcrumbsTest.php +++ b/tests/BreadcrumbsTest.php @@ -26,7 +26,25 @@ class BreadcrumbsTest extends TestCase HTML; + $this->assertEqualsWithoutLE($expected, $out); + } + public function testRenderWithoutHomeLink() + { + Breadcrumbs::$counter = 0; + $out = Breadcrumbs::widget([ + 'homeLink' => false, + 'links' => [ + ['label' => 'Library', 'url' => '#'], + ['label' => 'Data'] + ] + ]); + + $expected = << +HTML; $this->assertEqualsWithoutLE($expected, $out); }