Commit c330c0e2 authored by Razvan Grigore's avatar Razvan Grigore Committed by Alexander Makarov

Fixes #219, Fixes #171: Add ability to use custom HTML in navbar-header, Add...

Fixes #219, Fixes #171: Add ability to use custom HTML in navbar-header, Add ability to use a brandImage with the navbar
parent 7717fe67
......@@ -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
......
......@@ -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 <amigo.cobos@gmail.com>
* @author Alexander Kochetov <creocoder@gmail.com>
* @since 2.0
......@@ -57,9 +57,15 @@ 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
......@@ -72,6 +78,11 @@ class NavBar extends Widget
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/
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.
*/
......@@ -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;
......
......@@ -31,4 +31,32 @@ EXPECTED;
$this->assertEqualsWithoutLE($expected, $out);
}
public function testBrandImage()
{
$out = NavBar::widget([
'brandImage' => '/images/test.jpg',
'brandUrl' => '/',
]);
$this->assertContains('<a class="navbar-brand" href="/"><img src="/images/test.jpg" alt=""></a>', $out);
}
public function testHeaderContent()
{
$testContent = <<<HTML
<form class="navbar-form navbar-left">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
HTML;
$out = NavBar::widget([
'headerContent' => $testContent,
]);
$this->assertContains($testContent, $out);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment