Browse Source

Added `visible` option to `yii\bootstrap\Tab` widget items

tags/2.0.6
Klimov Paul 9 years ago
parent
commit
63ddbe87dd
  1. 1
      CHANGELOG.md
  2. 10
      Tabs.php
  3. 30
      tests/TabsTest.php

1
CHANGELOG.md

@ -5,6 +5,7 @@ Yii Framework 2 bootstrap extension Change Log
----------------------- -----------------------
- Enh #38: Added object support for `content` option in `Collapse` class (pana1990, ItsReddi) - Enh #38: Added object support for `content` option in `Collapse` class (pana1990, ItsReddi)
- Enh #40: Added `visible` option to `yii\bootstrap\Tab` widget items (klimov-paul)
2.0.4 May 10, 2015 2.0.4 May 10, 2015
------------------ ------------------

10
Tabs.php

@ -70,7 +70,9 @@ class Tabs extends Widget
* - url: string, optional, an external URL. When this is specified, clicking on this tab will bring * - url: string, optional, an external URL. When this is specified, clicking on this tab will bring
* the browser to this URL. This option is available since version 2.0.4. * the browser to this URL. This option is available since version 2.0.4.
* - options: array, optional, the HTML attributes of the tab pane container. * - options: array, optional, the HTML attributes of the tab pane container.
* - active: boolean, optional, whether the item tab header and pane should be visible or not. * - active: boolean, optional, whether this item tab header and pane should be active. If no item is marked as
* 'active' explicitly - the first one will be activated.
* - visible: boolean, optional, whether the item tab header and pane should be visible or not. Defaults to true.
* - items: array, optional, can be used instead of `content` to specify a dropdown items * - items: array, optional, can be used instead of `content` to specify a dropdown items
* configuration array. Each item can hold three extra keys, besides the above ones: * configuration array. Each item can hold three extra keys, besides the above ones:
* * active: boolean, optional, whether the item tab header and pane should be visible or not. * * active: boolean, optional, whether the item tab header and pane should be visible or not.
@ -148,6 +150,9 @@ class Tabs extends Widget
} }
foreach ($this->items as $n => $item) { foreach ($this->items as $n => $item) {
if (!ArrayHelper::remove($item, 'visible', true)) {
continue;
}
if (!array_key_exists('label', $item)) { if (!array_key_exists('label', $item)) {
throw new InvalidConfigException("The 'label' option is required."); throw new InvalidConfigException("The 'label' option is required.");
} }
@ -228,6 +233,9 @@ class Tabs extends Widget
if (is_string($item)) { if (is_string($item)) {
continue; continue;
} }
if (isset($item['visible']) && !$item['visible']) {
continue;
}
if (!array_key_exists('content', $item)) { if (!array_key_exists('content', $item)) {
throw new InvalidConfigException("The 'content' option is required."); throw new InvalidConfigException("The 'content' option is required.");
} }

30
tests/TabsTest.php

@ -76,4 +76,34 @@ class TabsTest extends TestCase
$this->assertContains($string, $out); $this->assertContains($string, $out);
} }
} }
public function testVisible()
{
Tabs::$counter = 0;
$html = Tabs::widget([
'items' => [
[
'label' => 'Page1', 'content' => 'Page1',
],
[
'label' => 'InvisiblePage',
'content' => 'Invisible Page Content',
'visible' => false
],
[
'label' => 'Dropdown1',
'items' => [
['label' => 'Page2', 'content' => 'Page2'],
['label' => 'InvisibleItem', 'content' => 'Invisible Item Content', 'visible' => false],
['label' => 'Page3', 'content' => 'Page3'],
]
],
]
]);
$this->assertNotContains('InvisiblePage', $html);
$this->assertNotContains('Invisible Page Content', $html);
$this->assertNotContains('InvisibleItem', $html);
$this->assertNotContains('Invisible Item Content', $html);
}
} }

Loading…
Cancel
Save