Skip to content

Commit

Permalink
Add attribute brandImageOptions to NavBar (#79)
Browse files Browse the repository at this point in the history
* Add attribute brandImageOptions to NavBar

* add Changelog message

---------

Co-authored-by: Max Kirmair <max.kirmair@waki-software.de>
  • Loading branch information
EvilKarter and EvilKarter authored Oct 20, 2023
1 parent cf7807d commit 1a4f4d6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ Yii Framework 2 bootstrap5 extension Change Log
2.0.5 under development
-----------------------

- Enh #78: Navbar has new attribute `brandImageOptions` (EvilKarter)
- Bug #74: Bootstrap5 Button is not registering clientEvents (simialbi)
- Bug #72: Nav::isItemActive(): Return value must be of type bool, int returned (hirenbhut93)
- Bug #62: Navbar can now accept `collapseOptions` to be `false` (theblindfrog)


2.0.4 November 30, 2022
-----------------------

Expand Down
8 changes: 7 additions & 1 deletion src/NavBar.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ class NavBar extends Widget
* @since 2.0.8
*/
public $brandImage = false;

/**
* @var array the HTML attributes of the brand image.
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/
public $brandImageOptions = [];
/**
* @var array|string|bool $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
Expand Down Expand Up @@ -144,7 +150,7 @@ public function init()
$this->offcanvasOptions['id'] = "{$this->options['id']}-offcanvas";
}
if ($this->brandImage !== false) {
$this->brandLabel = Html::img($this->brandImage);
$this->brandLabel = Html::img($this->brandImage, $this->brandImageOptions);
}
if ($this->brandLabel !== false) {
Html::addCssClass($this->brandOptions, ['widget' => 'navbar-brand']);
Expand Down
11 changes: 11 additions & 0 deletions tests/NavBarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ public function testBrandImage()

$this->assertContains('<a class="navbar-brand" href="/"><img src="/images/test.jpg" alt=""></a>', $out);
}

public function testBrandImageOptions()
{
$out = NavBar::widget([
'brandImage' => '/images/test.jpg',
'brandImageOptions' => ['alt' => 'test image'],
'brandUrl' => '/',
]);

$this->assertContains('<a class="navbar-brand" href="/"><img src="/images/test.jpg" alt="test image"></a>', $out);
}

public function testBrandLink()
{
Expand Down

0 comments on commit 1a4f4d6

Please sign in to comment.