Skip to content

Commit 9ec77ae

Browse files
author
Mikaël Capelle
committed
Move options of Navbar into a configuration.
1 parent 3fd2e6e commit 9ec77ae

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

src/View/Helper/BootstrapNavbarHelper.php

+19-12
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ class BootstrapNavbarHelper extends Helper {
2121

2222
use BootstrapTrait;
2323

24+
/**
25+
* Other helpers used by BootstrapNavbarHelper.
26+
*
27+
* @var array
28+
*/
2429
public $helpers = [
2530
'Html',
2631
'Form' => [
@@ -29,18 +34,19 @@ class BootstrapNavbarHelper extends Helper {
2934
];
3035

3136
/**
32-
* Automatic detection of active link (`class="active"`).
37+
* Default configuration for the helper.
3338
*
34-
* @var bool
35-
*/
36-
public $autoActiveLink = true;
37-
38-
/**
39-
* Automatic button link when not in a menu.
39+
* - `autoActiveLink` Set to `true` to automatically add `active` class
40+
* when given URL for a link matches the current URL. Default is `true`.
41+
* - `autoButtonLink` Set to true` to automatically create buttons instead
42+
* of links when outside a menu. Default is `true`.
4043
*
41-
* @var bool
44+
* @var array
4245
*/
43-
public $autoButtonLink = true;
46+
public $_defaultConfig = [
47+
'autoActiveLink' => true,
48+
'autoButtonLink' => true
49+
];
4450

4551
protected $_fixed = false;
4652
protected $_static = false;
@@ -172,11 +178,12 @@ public function create($brand, $options = []) {
172178
* @return string A HTML `<li>` tag wrapping the link.
173179
*/
174180
public function link($name, $url = '', array $options = [], array $linkOptions = []) {
175-
if ($this->_level == 0 && $this->autoButtonLink) {
176-
$options = $this->addClass($options, 'btn btn-default navbar-btn');
181+
if ($this->_level == 0 && $this->config('autoButtonLink')) {
182+
$options = $this->addClass($options, 'navbar-btn');
183+
$options = $this->addClass($options, 'btn btn-default');
177184
return $this->Html->link($name, $url, $options);
178185
}
179-
if (Router::url() == Router::url($url) && $this->autoActiveLink) {
186+
if (Router::url() == Router::url($url) && $this->config('autoActiveLink')) {
180187
$options = $this->addClass($options, 'active');
181188
}
182189
return $this->Html->tag('li', $this->Html->link($name, $url, $linkOptions),

0 commit comments

Comments
 (0)