From 72da96e3af490bbb240fd04c32bb445dcb5421ae Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Thu, 23 Apr 2015 17:50:08 +0300 Subject: [PATCH 01/16] Added note on ButtonGroup values handling --- ButtonGroup.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ButtonGroup.php b/ButtonGroup.php index c440ad2..560ad13 100644 --- a/ButtonGroup.php +++ b/ButtonGroup.php @@ -33,8 +33,12 @@ use yii\helpers\Html; * ] * ]); * ``` + * + * Pressing on the button should be handled via JavaScript. See the following for details: + * * @see http://getbootstrap.com/javascript/#buttons * @see http://getbootstrap.com/components/#btn-groups + * * @author Antonio Ramirez * @since 2.0 */ From dc95bd562d45f5d748ba3aca6b392fbc6055c7b9 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Wed, 29 Apr 2015 10:58:59 +0200 Subject: [PATCH 02/16] adjusted composer.json links --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index fde1a87..3818768 100644 --- a/composer.json +++ b/composer.json @@ -5,11 +5,11 @@ "type": "yii2-extension", "license": "BSD-3-Clause", "support": { - "issues": "https://github.com/yiisoft/yii2/issues?labels=ext%3Abootstrap", + "issues": "https://github.com/yiisoft/yii2-bootstrap/issues", "forum": "http://www.yiiframework.com/forum/", "wiki": "http://www.yiiframework.com/wiki/", "irc": "irc://irc.freenode.net/yii", - "source": "https://github.com/yiisoft/yii2" + "source": "https://github.com/yiisoft/yii2-bootstrap" }, "authors": [ { From 554c3ccf04ee0c5ae699615d2866d8a6826d1ffb Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Wed, 29 Apr 2015 23:05:49 -0400 Subject: [PATCH 03/16] =?UTF-8?q?Added=20support=20for=20using=20external?= =?UTF-8?q?=20URLs=20for=20=0D=1B[3g=1BH=20=20=20=20=20=20=20=20=1BH=20=20?= =?UTF-8?q?=20=20=20=20=20=20=1BH=20=20=20=20=20=20=20=20=1BH=20=20=20=20?= =?UTF-8?q?=20=20=20=20=1BH=20=20=20=20=20=20=20=20=1BH=20=20=20=20=20=20?= =?UTF-8?q?=20=20=1BH=20=20=20=20=20=20=20=20=1BH=20=20=20=20=20=20=20=20?= =?UTF-8?q?=1BH=20=20=20=20=20=20=20=20=1BH=20=20=20=20=20=20=20=20=1BH=20?= =?UTF-8?q?=20=20=20=20=20=20=20=1BH=20=20=20=20=20=20=20=20=1BH?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + Tabs.php | 16 ++++++++++++++-- tests/TabsTest.php | 7 ++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fd7214c..1f4fd0f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ Yii Framework 2 bootstrap extension Change Log - Enh #2546: Added `visible` option to `yii\bootstrap\ButtonGroup::$buttons` (samdark, lukBarros) - Enh #7633: Added `ActionColumn::$buttonOptions` for defining HTML options to be added to the default buttons (cebe) - Enh: Added `Nav::$dropDownCaret` to allow customization of the dropdown caret symbol (cebe) +- Enh: Added support for using external URLs for `Tabs`. (dynasource, qiangxue) 2.0.3 March 01, 2015 diff --git a/Tabs.php b/Tabs.php index 0f8d6c9..6e244c6 100644 --- a/Tabs.php +++ b/Tabs.php @@ -31,6 +31,10 @@ use yii\helpers\Html; * 'options' => ['id' => 'myveryownID'], * ], * [ + * 'label' => 'Example', + * 'url' => 'http://www.example.com', + * ], + * [ * 'label' => 'Dropdown', * 'items' => [ * [ @@ -63,6 +67,8 @@ class Tabs extends Widget * - headerOptions: array, optional, the HTML attributes of the tab header. * - linkOptions: array, optional, the HTML attributes of the tab header link tags. * - content: string, optional, the content (HTML) of the tab pane. + * - 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. * - 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. * - items: array, optional, can be used instead of `content` to specify a dropdown items @@ -171,8 +177,14 @@ class Tabs extends Widget Html::addCssClass($options, 'active'); Html::addCssClass($headerOptions, 'active'); } - $linkOptions['data-toggle'] = 'tab'; - $header = Html::a($label, '#' . $options['id'], $linkOptions); + + if (isset($item['url'])) { + $header = Html::a($label, $item['url'], $linkOptions); + } else { + $linkOptions['data-toggle'] = 'tab'; + $header = Html::a($label, '#' . $options['id'], $linkOptions); + } + if ($this->renderTabContent) { $panes[] = Html::tag('div', isset($item['content']) ? $item['content'] : '', $options); } diff --git a/tests/TabsTest.php b/tests/TabsTest.php index 18e39c7..4f61098 100644 --- a/tests/TabsTest.php +++ b/tests/TabsTest.php @@ -2,6 +2,7 @@ namespace yiiunit\extensions\bootstrap; use yii\bootstrap\Tabs; +use yii\helpers\Html; /** * Tests for Tabs widget @@ -36,7 +37,10 @@ class TabsTest extends TestCase ['label' => 'Page4', 'content' => 'Page4'], ['label' => 'Page5', 'content' => 'Page5'], ] - ] + ], + [ + 'label' => $extAnchor = 'External link', 'url' => $extUrl = ['//other/route'], + ], ] ]); @@ -65,6 +69,7 @@ class TabsTest extends TestCase "id=\"$page3\"", "id=\"$page4\"", "id=\"$page5\"", + Html::a($extAnchor,$extUrl), ]; foreach ($shouldContain as $string) { From 37b1b59817e76556faac9f4414b5c20f5e5db278 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Thu, 30 Apr 2015 11:00:07 +0200 Subject: [PATCH 04/16] ensure widget configuration are reusable Configuration where not preserved when used multiple times. fixes yiisoft/yii2#8231 --- Alert.php | 12 ++++++------ ButtonDropdown.php | 2 +- CHANGELOG.md | 1 + Modal.php | 24 ++++++++++++------------ 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/Alert.php b/Alert.php index 287385a..fdd8979 100644 --- a/Alert.php +++ b/Alert.php @@ -117,14 +117,14 @@ class Alert extends Widget */ protected function renderCloseButton() { - if ($this->closeButton !== false) { - $tag = ArrayHelper::remove($this->closeButton, 'tag', 'button'); - $label = ArrayHelper::remove($this->closeButton, 'label', '×'); - if ($tag === 'button' && !isset($this->closeButton['type'])) { - $this->closeButton['type'] = 'button'; + if (($closeButton = $this->closeButton) !== false) { + $tag = ArrayHelper::remove($closeButton, 'tag', 'button'); + $label = ArrayHelper::remove($closeButton, 'label', '×'); + if ($tag === 'button' && !isset($closeButton['type'])) { + $closeButton['type'] = 'button'; } - return Html::tag($tag, $label, $this->closeButton); + return Html::tag($tag, $label, $closeButton); } else { return null; } diff --git a/ButtonDropdown.php b/ButtonDropdown.php index 3d74a5b..8796fc6 100644 --- a/ButtonDropdown.php +++ b/ButtonDropdown.php @@ -81,7 +81,7 @@ class ButtonDropdown extends Widget $this->registerPlugin('button'); return implode("\n", [ - Html::beginTag($tag, $this->containerOptions), + Html::beginTag($tag, $options), $this->renderButton(), $this->renderDropdown(), Html::endTag($tag) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f4fd0f..896fe98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Yii Framework 2 bootstrap extension Change Log - Bug #18: `label` option ignored by `yii\bootstrap\Activefield::checkbox()` and `yii\bootstrap\Activefield::radio()` (mikehaertl) - Bug #5984: `yii\bootstrap\Activefield::checkbox()` caused browser to link label to the wrong input (cebe) - Bug #7894: Fixed incorrect URL config processing at `yii\bootstrap\Nav::items` if route element is not a first one (nkovacs, klimov-paul) +- Bug #8231: Configuration of Alert, ButtonDropdown, Modal widget where not preserved when used multiple times (cebe, idMolotov) - Enh #29: Added support to list-groups for Collapse class (pana1990, skullcrasher) - Enh #2546: Added `visible` option to `yii\bootstrap\ButtonGroup::$buttons` (samdark, lukBarros) - Enh #7633: Added `ActionColumn::$buttonOptions` for defining HTML options to be added to the default buttons (cebe) diff --git a/Modal.php b/Modal.php index ccb6229..70e8d41 100644 --- a/Modal.php +++ b/Modal.php @@ -182,14 +182,14 @@ class Modal extends Widget */ protected function renderToggleButton() { - if ($this->toggleButton !== false) { - $tag = ArrayHelper::remove($this->toggleButton, 'tag', 'button'); - $label = ArrayHelper::remove($this->toggleButton, 'label', 'Show'); - if ($tag === 'button' && !isset($this->toggleButton['type'])) { - $this->toggleButton['type'] = 'button'; + if (($toggleButton = $this->toggleButton) !== false) { + $tag = ArrayHelper::remove($toggleButton, 'tag', 'button'); + $label = ArrayHelper::remove($toggleButton, 'label', 'Show'); + if ($tag === 'button' && !isset($toggleButton['type'])) { + $toggleButton['type'] = 'button'; } - return Html::tag($tag, $label, $this->toggleButton); + return Html::tag($tag, $label, $toggleButton); } else { return null; } @@ -201,14 +201,14 @@ class Modal extends Widget */ protected function renderCloseButton() { - if ($this->closeButton !== false) { - $tag = ArrayHelper::remove($this->closeButton, 'tag', 'button'); - $label = ArrayHelper::remove($this->closeButton, 'label', '×'); - if ($tag === 'button' && !isset($this->closeButton['type'])) { - $this->closeButton['type'] = 'button'; + if (($closeButton = $this->closeButton) !== false) { + $tag = ArrayHelper::remove($closeButton, 'tag', 'button'); + $label = ArrayHelper::remove($closeButton, 'label', '×'); + if ($tag === 'button' && !isset($closeButton['type'])) { + $closeButton['type'] = 'button'; } - return Html::tag($tag, $label, $this->closeButton); + return Html::tag($tag, $label, $closeButton); } else { return null; } From 6e621de81ed81813f925ce30197e4a23f3be6816 Mon Sep 17 00:00:00 2001 From: Lucas Barros Date: Thu, 30 Apr 2015 16:22:02 -0300 Subject: [PATCH 05/16] Change term transleted Change term transleted --- docs/guide-pt-BR/installation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/guide-pt-BR/installation.md b/docs/guide-pt-BR/installation.md index 5d2e343..b49d7cc 100644 --- a/docs/guide-pt-BR/installation.md +++ b/docs/guide-pt-BR/installation.md @@ -1,4 +1,4 @@ -Installation +Instalação ============ ## Instalando através do composer From e4263ee959e637eb9a1163ecc4829b222ecf1cb0 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Sun, 3 May 2015 23:58:00 +0200 Subject: [PATCH 06/16] added Makefile for docker based test --- .gitignore | 6 ++++++ Makefile | 26 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 Makefile diff --git a/.gitignore b/.gitignore index da1422a..87ce278 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,9 @@ composer.phar phpunit.phar # local phpunit config /phpunit.xml + +/tests/runtime +/tests/data/config.local.php +/tests/docker +/tests/dockerids + diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..16372e7 --- /dev/null +++ b/Makefile @@ -0,0 +1,26 @@ + +# default versions to test against +# these can be overridden by setting the environment variables in the shell +PHP_VERSION=php-5.6.8 +YII_VERSION=dev-master + +# ensure all the configuration variables above are in environment of the shell commands below +export + +help: + @echo "make test - run phpunit tests using a docker environment" +# @echo "make clean - stop docker and remove container" + +test: docker-php + composer require "yiisoft/yii2:${YII_VERSION}" --prefer-dist + composer install --prefer-dist + docker run --rm=true -v $(shell pwd):/opt/test yiitest/php:${PHP_VERSION} phpunit --verbose --color + +docker-php: dockerfiles + cd tests/docker/php && sh build.sh + +dockerfiles: + test -d tests/docker || git clone https://github.com/cebe/jenkins-test-docker tests/docker + cd tests/docker && git checkout -- . && git pull + mkdir -p tests/dockerids + From b7c7e74dedf063717637fdb446fc7c11d89fe340 Mon Sep 17 00:00:00 2001 From: Lucas Barros Date: Wed, 6 May 2015 01:07:06 -0300 Subject: [PATCH 07/16] Change terms transleted Change terms transleted - First Revision close #37 --- docs/guide-pt-BR/basic-usage.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/guide-pt-BR/basic-usage.md b/docs/guide-pt-BR/basic-usage.md index ab0e6a4..472e8bf 100644 --- a/docs/guide-pt-BR/basic-usage.md +++ b/docs/guide-pt-BR/basic-usage.md @@ -1,8 +1,8 @@ Uso Básico =========== -O Yii Não registra os básico componentes básicos do bootstrap em código PHP visto que esse HTML é muito simples, por si só. -Você pode encontrar detalhes sobre como usar o básico no [site documentação do bootstrap] (http://getbootstrap.com/css/). O Yii ainda fornece uma +O Yii Não registra os componentes básicos do bootstrap em código PHP visto que esse HTML é muito simples, por si só. +Você pode encontrar detalhes sobre como usar o básico no [site documentação do Bootstrap] (http://getbootstrap.com/css/). O Yii ainda fornece uma forma conveniente para incluir assets de bootstrap em suas páginas com uma única linha adicionado ao arquivo `AppAsset.php` localizado no seu diretório `@app/assets`: From 032ac86999ad4784400f91165282a33755e69b82 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Wed, 6 May 2015 16:18:56 +0200 Subject: [PATCH 08/16] updated fxp/composer-asset-plugin version constraint --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 2321510..a94ff31 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,7 +26,7 @@ cache: install: - travis_retry composer self-update && composer --version - - travis_retry composer global require "fxp/composer-asset-plugin:1.0.0" + - travis_retry composer global require "fxp/composer-asset-plugin:~1.0.0" - export PATH="$HOME/.composer/vendor/bin:$PATH" - travis_retry composer install --prefer-dist --no-interaction From 898682b04c326906ad5f818c013b604723e1a9fc Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Sat, 9 May 2015 23:43:16 -0400 Subject: [PATCH 09/16] Using `Json::htmlEncode()` for safer JSON data encoding in HTML code --- CHANGELOG.md | 1 + Widget.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 896fe98..18cf504 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ Yii Framework 2 bootstrap extension Change Log - Bug #5984: `yii\bootstrap\Activefield::checkbox()` caused browser to link label to the wrong input (cebe) - Bug #7894: Fixed incorrect URL config processing at `yii\bootstrap\Nav::items` if route element is not a first one (nkovacs, klimov-paul) - Bug #8231: Configuration of Alert, ButtonDropdown, Modal widget where not preserved when used multiple times (cebe, idMolotov) +- Bug (CVE-2015-3397): Using `Json::htmlEncode()` for safer JSON data encoding in HTML code (samdark, Tomasz Tokarski) - Enh #29: Added support to list-groups for Collapse class (pana1990, skullcrasher) - Enh #2546: Added `visible` option to `yii\bootstrap\ButtonGroup::$buttons` (samdark, lukBarros) - Enh #7633: Added `ActionColumn::$buttonOptions` for defining HTML options to be added to the default buttons (cebe) diff --git a/Widget.php b/Widget.php index 641f640..dc07f4f 100644 --- a/Widget.php +++ b/Widget.php @@ -66,7 +66,7 @@ class Widget extends \yii\base\Widget $id = $this->options['id']; if ($this->clientOptions !== false) { - $options = empty($this->clientOptions) ? '' : Json::encode($this->clientOptions); + $options = empty($this->clientOptions) ? '' : Json::htmlEncode($this->clientOptions); $js = "jQuery('#$id').$name($options);"; $view->registerJs($js); } From a060799e77762cb6856452496e80c5dee3ae7e56 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Sun, 10 May 2015 13:41:22 -0400 Subject: [PATCH 10/16] doc adjustment --- ButtonGroup.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ButtonGroup.php b/ButtonGroup.php index 560ad13..c99312f 100644 --- a/ButtonGroup.php +++ b/ButtonGroup.php @@ -38,7 +38,7 @@ use yii\helpers\Html; * * @see http://getbootstrap.com/javascript/#buttons * @see http://getbootstrap.com/components/#btn-groups - * + * * @author Antonio Ramirez * @since 2.0 */ From 1b6b1e61cf91c3cdd517d6a7e71d30bb212e4af0 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Sun, 10 May 2015 18:08:17 -0400 Subject: [PATCH 11/16] 2.0.4 release --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 3818768..b3ff507 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ } ], "require": { - "yiisoft/yii2": "*", + "yiisoft/yii2": ">=2.0.4", "bower-asset/bootstrap": "3.3.* | 3.2.* | 3.1.*" }, "autoload": { From 551a391dd8879efea34b96f5a19fd85302e58a6f Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Sun, 10 May 2015 18:27:54 -0400 Subject: [PATCH 12/16] prepare for next release --- CHANGELOG.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 18cf504..ef8d6e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,14 @@ Yii Framework 2 bootstrap extension Change Log ============================================== -2.0.4 under development +2.0.5 under development ----------------------- + + +2.0.4 May 10, 2015 +------------------ + - Bug #18: `label` option ignored by `yii\bootstrap\Activefield::checkbox()` and `yii\bootstrap\Activefield::radio()` (mikehaertl) - Bug #5984: `yii\bootstrap\Activefield::checkbox()` caused browser to link label to the wrong input (cebe) - Bug #7894: Fixed incorrect URL config processing at `yii\bootstrap\Nav::items` if route element is not a first one (nkovacs, klimov-paul) From f7cc408d88191b84da4c83da130ba285a7306153 Mon Sep 17 00:00:00 2001 From: pana1990 Date: Mon, 11 May 2015 21:32:13 +0200 Subject: [PATCH 13/16] Fix 29: Added support to object for content option in Collapse class --- CHANGELOG.md | 2 +- Collapse.php | 6 +++--- tests/CollapseTest.php | 35 +++++++++++++++++++++++++++++++++++ tests/data/Singer.php | 27 +++++++++++++++++++++++++++ 4 files changed, 66 insertions(+), 4 deletions(-) create mode 100644 tests/data/Singer.php diff --git a/CHANGELOG.md b/CHANGELOG.md index ef8d6e8..333db71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ Yii Framework 2 bootstrap extension Change Log 2.0.5 under development ----------------------- - +- Enh #38: Added support to object for content option in Collapse class (pana1990, ItsReddi) 2.0.4 May 10, 2015 ------------------ diff --git a/Collapse.php b/Collapse.php index a2f237a..c45e966 100644 --- a/Collapse.php +++ b/Collapse.php @@ -61,7 +61,7 @@ class Collapse extends Widget * - label: string, required, the group header label. * - encode: boolean, optional, whether this label should be HTML-encoded. This param will override * global `$this->encodeLabels` param. - * - content: array|string, required, the content (HTML) of the group + * - content: array|string|object, required, the content (HTML) of the group * - options: array, optional, the HTML attributes of the group * - contentOptions: optional, the HTML attributes of the group's content */ @@ -146,7 +146,7 @@ class Collapse extends Widget $header = Html::tag('h4', $headerToggle, ['class' => 'panel-title']); - if (is_string($item['content'])) { + if (is_string($item['content']) || is_object($item['content'])) { $content = Html::tag('div', $item['content'], ['class' => 'panel-body']) . "\n"; } elseif (is_array($item['content'])) { $content = Html::ul($item['content'], [ @@ -160,7 +160,7 @@ class Collapse extends Widget $content .= Html::tag('div', $item['footer'], ['class' => 'panel-footer']) . "\n"; } } else { - throw new InvalidConfigException('The "content" option should be a string or array.'); + throw new InvalidConfigException('The "content" option should be a string, array or object.'); } } else { throw new InvalidConfigException('The "content" option is required.'); diff --git a/tests/CollapseTest.php b/tests/CollapseTest.php index 8c294b3..aa703bc 100644 --- a/tests/CollapseTest.php +++ b/tests/CollapseTest.php @@ -108,4 +108,39 @@ class CollapseTest extends TestCase HTML , $output); } + + /** + * @see https://github.com/yiisoft/yii2/issues/8357 + */ + public function testRenderObject() + { + $template = ['template' => '{input}']; + ob_start(); + $form = \yii\widgets\ActiveForm::begin(['action' => '/something']); + ob_end_clean(); + $model = new data\Singer; + + Collapse::$counter = 0; + $output = Collapse::widget([ + 'items' => [ + [ + 'label' => 'Collapsible Group Item #1', + 'content' => $form->field($model, 'firstName', $template) + ], + ] + ]); + + $this->assertEqualsWithoutLE(<< + + + +HTML + , $output); + } } diff --git a/tests/data/Singer.php b/tests/data/Singer.php new file mode 100644 index 0000000..bd8e15e --- /dev/null +++ b/tests/data/Singer.php @@ -0,0 +1,27 @@ + + */ +class Singer extends Model +{ + public $firstName; + public $lastName; + public $test; + + public function rules() + { + return [ + [['lastName'], 'default', 'value' => 'Lennon'], + [['lastName'], 'required'], + [['underscore_style'], 'yii\captcha\CaptchaValidator'], + [['test'], 'required', 'when' => function($model) { return $model->firstName === 'cebe'; }], + ]; + } +} From 29ed43dd05df05cb15431503b66cd5ef2fab8a0d Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Tue, 12 May 2015 11:39:27 +0300 Subject: [PATCH 14/16] Adjusted changelog wording --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 333db71..0c12d53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ Yii Framework 2 bootstrap extension Change Log 2.0.5 under development ----------------------- -- Enh #38: Added support to object for content option in Collapse class (pana1990, ItsReddi) +- Enh #38: Added object support for `content` option in `Collapse` class (pana1990, ItsReddi) 2.0.4 May 10, 2015 ------------------ From 63ddbe87dd4bb56660294565ae361be3530bc986 Mon Sep 17 00:00:00 2001 From: Klimov Paul Date: Fri, 15 May 2015 12:17:22 +0300 Subject: [PATCH 15/16] Added `visible` option to `yii\bootstrap\Tab` widget items --- CHANGELOG.md | 1 + Tabs.php | 10 +++++++++- tests/TabsTest.php | 30 ++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c12d53..094c6e1 100644 --- a/CHANGELOG.md +++ b/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 #40: Added `visible` option to `yii\bootstrap\Tab` widget items (klimov-paul) 2.0.4 May 10, 2015 ------------------ diff --git a/Tabs.php b/Tabs.php index 6e244c6..c31c120 100644 --- a/Tabs.php +++ b/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 * 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. - * - 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 * 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. @@ -148,6 +150,9 @@ class Tabs extends Widget } foreach ($this->items as $n => $item) { + if (!ArrayHelper::remove($item, 'visible', true)) { + continue; + } if (!array_key_exists('label', $item)) { throw new InvalidConfigException("The 'label' option is required."); } @@ -228,6 +233,9 @@ class Tabs extends Widget if (is_string($item)) { continue; } + if (isset($item['visible']) && !$item['visible']) { + continue; + } if (!array_key_exists('content', $item)) { throw new InvalidConfigException("The 'content' option is required."); } diff --git a/tests/TabsTest.php b/tests/TabsTest.php index 4f61098..43b432c 100644 --- a/tests/TabsTest.php +++ b/tests/TabsTest.php @@ -76,4 +76,34 @@ class TabsTest extends TestCase $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); + } } From f387e6ebfdfc3621ff7f6aa52f168f26562b6eb0 Mon Sep 17 00:00:00 2001 From: Klimov Paul Date: Fri, 15 May 2015 13:20:11 +0300 Subject: [PATCH 16/16] Added `submenuOptions` support at `yii\bootstrap\Dropdown` --- CHANGELOG.md | 1 + Dropdown.php | 22 +++++++++++++++++++--- tests/DropdownTest.php | 42 +++++++++++++++++++++++++++++++++++++++++- 3 files changed, 61 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 094c6e1..7e351e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ Yii Framework 2 bootstrap extension Change Log - 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) +- Enh #41: Added `submenuOptions` support at `yii\bootstrap\Dropdown` (spikyjt, klimov-paul) 2.0.4 May 10, 2015 ------------------ diff --git a/Dropdown.php b/Dropdown.php index 7537b7b..35e12cd 100644 --- a/Dropdown.php +++ b/Dropdown.php @@ -48,6 +48,8 @@ class Dropdown extends Widget * - options: array, optional, the HTML attributes of the item. * - items: array, optional, the submenu items. The structure is the same as this property. * Note that Bootstrap doesn't support dropdown submenu. You have to add your own CSS styles to support it. + * - submenuOptions: array, optional, the HTML attributes for sub-menu container tag. If specified it will be + * merged with [[submenuOptions]]. * * To insert divider use ``. */ @@ -56,6 +58,12 @@ class Dropdown extends Widget * @var boolean whether the labels for header items should be HTML-encoded. */ public $encodeLabels = true; + /** + * @var array|null the HTML attributes for sub-menu container tags. + * If not set - [[options]] value will be used for it. + * @since 2.0.5 + */ + public $submenuOptions; /** @@ -64,6 +72,12 @@ class Dropdown extends Widget */ public function init() { + if ($this->submenuOptions === null) { + // copying of [[options]] kept for BC + // @todo separate [[submenuOptions]] from [[options]] completely before 2.1 release + $this->submenuOptions = $this->options; + unset($this->submenuOptions['id']); + } parent::init(); Html::addCssClass($this->options, 'dropdown-menu'); } @@ -88,7 +102,7 @@ class Dropdown extends Widget protected function renderItems($items, $options = []) { $lines = []; - foreach ($items as $i => $item) { + foreach ($items as $item) { if (isset($item['visible']) && !$item['visible']) { continue; } @@ -113,8 +127,10 @@ class Dropdown extends Widget $content = Html::a($label, $url, $linkOptions); } } else { - $submenuOptions = $options; - unset($submenuOptions['id']); + $submenuOptions = $this->submenuOptions; + if (isset($item['submenuOptions'])) { + $submenuOptions = array_merge($submenuOptions, $item['submenuOptions']); + } $content = Html::a($label, $url === null ? '#' : $url, $linkOptions) . $this->renderItems($item['items'], $submenuOptions); Html::addCssClass($itemOptions, 'dropdown-submenu'); diff --git a/tests/DropdownTest.php b/tests/DropdownTest.php index ef284e6..f0f4f45 100644 --- a/tests/DropdownTest.php +++ b/tests/DropdownTest.php @@ -41,10 +41,50 @@ class DropdownTest extends TestCase $expected = << - + +EXPECTED; + + $this->assertEqualsWithoutLE($expected, $out); + } }