From e4a3d3511960a4e4706c62e6efe0af9ae0c0e5cc Mon Sep 17 00:00:00 2001 From: Nikolas Grottendieck Date: Mon, 11 Jul 2016 22:00:23 +0200 Subject: [PATCH 1/4] Allow URLs to be used instead of content for Tab Widget Dropdown items Fixes #113 --- Tabs.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Tabs.php b/Tabs.php index 3044f11..e671184 100644 --- a/Tabs.php +++ b/Tabs.php @@ -44,6 +44,10 @@ use yii\helpers\ArrayHelper; * 'label' => 'DropdownB', * 'content' => 'DropdownB, Anim pariatur cliche...', * ], + * [ + * 'label' => 'External Link', + * 'url' => 'http://www.example.com', + * ], * ], * ], * ], @@ -240,8 +244,11 @@ class Tabs extends Widget if (isset($item['visible']) && !$item['visible']) { continue; } - if (!array_key_exists('content', $item)) { - throw new InvalidConfigException("The 'content' option is required."); + if (!(array_key_exists('content', $item) xor array_key_exists('url', $item))) { + throw new InvalidConfigException("Either the 'content' or the 'url' option is required."); + } + if (array_key_exists('url', $item)) { + continue; } $content = ArrayHelper::remove($item, 'content'); From 91607a2271186052d93969c99c13b90a83365545 Mon Sep 17 00:00:00 2001 From: Nikolas Grottendieck Date: Mon, 11 Jul 2016 22:01:23 +0200 Subject: [PATCH 2/4] Test cases updated to cover enhanced Tab Widget Dropdown items See #113 --- tests/TabsTest.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tests/TabsTest.php b/tests/TabsTest.php index 08e37a6..06fd3b3 100644 --- a/tests/TabsTest.php +++ b/tests/TabsTest.php @@ -39,7 +39,13 @@ class TabsTest extends TestCase ] ], [ - 'label' => $extAnchor = 'External link', 'url' => $extUrl = ['//other/route'], + 'label' => $extAnchor1 = 'External link', 'url' => $extUrl1 = ['//other/route'], + ], + [ + 'label' => 'Dropdown3', + 'items' => [ + ['label' => $extAnchor2 = 'External Dropdown Link', 'url' => $extUrl2 = ['//other/dropdown/route']], + ] ], ] ]); @@ -63,13 +69,16 @@ class TabsTest extends TestCase "#$page4", // Page4 "#$page5", // Page5 + 'w3', // Dropdown3 + // containers "id=\"$page1\"", "id=\"$page2\"", "id=\"$page3\"", "id=\"$page4\"", "id=\"$page5\"", - Html::a($extAnchor,$extUrl), + Html::a($extAnchor1,$extUrl1), + Html::a($extAnchor2,$extUrl2, ['tabindex' => -1]), ]; foreach ($shouldContain as $string) { @@ -96,6 +105,8 @@ class TabsTest extends TestCase ['label' => 'Page2', 'content' => 'Page2'], ['label' => 'InvisibleItem', 'content' => 'Invisible Item Content', 'visible' => false], ['label' => 'Page3', 'content' => 'Page3'], + ['label' => 'External Link', 'url' => ['//other/dropdown/route']], + ['label' => 'Invisible External Link', 'url' => ['//other/dropdown/route'], 'visible' => false], ] ], ] @@ -105,6 +116,7 @@ class TabsTest extends TestCase $this->assertNotContains('Invisible Page Content', $html); $this->assertNotContains('InvisibleItem', $html); $this->assertNotContains('Invisible Item Content', $html); + $this->assertNotContains('Invisible External Link', $html); } public function testItem() From a34585b2c48844c50985c7a032a754da1327f192 Mon Sep 17 00:00:00 2001 From: Nikolas Grottendieck Date: Mon, 11 Jul 2016 22:02:04 +0200 Subject: [PATCH 3/4] Changelog updated to list enhanced Tab Widget Dropdown items See #113 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e451e30..829d237 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Yii Framework 2 bootstrap extension Change Log - Bug #126: `yii\bootstrap\ToggleButtonGroup` was unable to work without model (makroxyz) - Bug #130: Fixed `yii\bootstrap\Collapse` to use pure numerical value on `content` property (meysampg) - Bug #137: Remove `role="navbar"` from `yii\bootstrap\NavBar` according to new aria specification (tino415) +- Enh #113: Allow URLs instead of content for Tab Widget Dropdown items (Okeanos) 2.0.6 March 17, 2016 -------------------- From 72a9bf387147c269d149469d9de595637189c919 Mon Sep 17 00:00:00 2001 From: Nikolas Grottendieck Date: Tue, 12 Jul 2016 00:05:01 +0200 Subject: [PATCH 4/4] Changed error message for content/url option in Tab Widget Dropdown items to be more specific based on feedback by @cebe --- Tabs.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tabs.php b/Tabs.php index e671184..8872981 100644 --- a/Tabs.php +++ b/Tabs.php @@ -245,7 +245,7 @@ class Tabs extends Widget continue; } if (!(array_key_exists('content', $item) xor array_key_exists('url', $item))) { - throw new InvalidConfigException("Either the 'content' or the 'url' option is required."); + throw new InvalidConfigException("Either the 'content' or the 'url' option is required, but only one can be set."); } if (array_key_exists('url', $item)) { continue;