diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e3d6b5..9324d4c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,8 @@ Yii Framework 2 bootstrap extension Change Log 2.0.8 under development ----------------------- -- no changes in this release. +- Enh #219: Add ability to use custom HTML in navbar-header (razvanphp) +- Enh #171: Add ability to use a brandImage with the navbar (razvanphp) 2.0.7 October 09, 2017 diff --git a/NavBar.php b/NavBar.php index fa7a807..a1013c5 100644 --- a/NavBar.php +++ b/NavBar.php @@ -32,7 +32,7 @@ use yii\helpers\ArrayHelper; * NavBar::end(); * ``` * - * @see http://getbootstrap.com/components/#navbar + * @see https://getbootstrap.com/docs/3.3/components/#navbar * @author Antonio Ramirez * @author Alexander Kochetov * @since 2.0 @@ -57,10 +57,16 @@ class NavBar extends Widget public $containerOptions = []; /** * @var string|boolean the text of the brand or false if it's not used. Note that this is not HTML-encoded. - * @see http://getbootstrap.com/components/#navbar + * @see https://getbootstrap.com/docs/3.3/components/#navbar */ public $brandLabel = false; /** + * @var string|boolean src of the brand image or false if it's not used. Note that this param will override `$this->brandLabel` param. + * @see https://getbootstrap.com/docs/3.3/components/#navbar + * @since 2.0.8 + */ + public $brandImage = false; + /** * @var array|string|boolean $url the URL for the brand's hyperlink tag. This parameter will be processed by [[\yii\helpers\Url::to()]] * and will be used for the "href" attribute of the brand link. Default value is false that means * [[\yii\web\Application::homeUrl]] will be used. @@ -73,6 +79,11 @@ class NavBar extends Widget */ public $brandOptions = []; /** + * @var string HTML content to be added in navbar-header div, for example, mobile search form. + * @since 2.0.8 + */ + public $headerContent; + /** * @var string text to show for screen readers for the button to toggle the navbar. */ public $screenReaderToggleText = 'Toggle navigation'; @@ -114,10 +125,14 @@ class NavBar extends Widget $this->containerOptions['id'] = "{$this->options['id']}-collapse"; } echo $this->renderToggleButton(); + if ($this->brandImage !== false) { + $this->brandLabel = Html::img($this->brandImage); + } if ($this->brandLabel !== false) { Html::addCssClass($this->brandOptions, ['widget' => 'navbar-brand']); echo Html::a($this->brandLabel, $this->brandUrl === false ? Yii::$app->homeUrl : $this->brandUrl, $this->brandOptions); } + echo $this->headerContent; echo Html::endTag('div'); Html::addCssClass($this->containerOptions, ['collapse' => 'collapse', 'widget' => 'navbar-collapse']); $options = $this->containerOptions; diff --git a/tests/NavBarTest.php b/tests/NavBarTest.php index 3734a63..04d8f6c 100644 --- a/tests/NavBarTest.php +++ b/tests/NavBarTest.php @@ -31,4 +31,32 @@ EXPECTED; $this->assertEqualsWithoutLE($expected, $out); } + + public function testBrandImage() + { + $out = NavBar::widget([ + 'brandImage' => '/images/test.jpg', + 'brandUrl' => '/', + ]); + + $this->assertContains('', $out); + } + + public function testHeaderContent() + { + $testContent = << +
+ +
+ + +HTML; + + $out = NavBar::widget([ + 'headerContent' => $testContent, + ]); + + $this->assertContains($testContent, $out); + } }