diff --git a/ButtonGroup.php b/ButtonGroup.php index c4459a0..c440ad2 100644 --- a/ButtonGroup.php +++ b/ButtonGroup.php @@ -7,6 +7,7 @@ namespace yii\bootstrap; +use yii\helpers\ArrayHelper; use yii\helpers\Html; /** @@ -20,6 +21,7 @@ use yii\helpers\Html; * 'buttons' => [ * ['label' => 'A'], * ['label' => 'B'], + * ['label' => 'C', 'visible' => false], * ] * ]); * @@ -44,6 +46,7 @@ class ButtonGroup extends Widget * * - label: string, required, the button label. * - options: array, optional, the HTML attributes of the button. + * - visible: boolean, optional, whether this button is visible. Defaults to true. */ public $buttons = []; /** @@ -80,6 +83,11 @@ class ButtonGroup extends Widget $buttons = []; foreach ($this->buttons as $button) { if (is_array($button)) { + $visible = ArrayHelper::remove($button, 'visible', true); + if ($visible === false) { + continue; + } + $button['view'] = $this->getView(); if (!isset($button['encodeLabel'])) { $button['encodeLabel'] = $this->encodeLabels; diff --git a/CHANGELOG.md b/CHANGELOG.md index 569d6ea..9c5b2f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,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) +- 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) diff --git a/tests/ButtonGroupTest.php b/tests/ButtonGroupTest.php new file mode 100644 index 0000000..a38a65b --- /dev/null +++ b/tests/ButtonGroupTest.php @@ -0,0 +1,29 @@ + [ + ['label' => 'button-A'], + ['label' => 'button-B', 'visible' => true], + ['label' => 'button-C', 'visible' => false], + Button::widget(['label' => 'button-D']), + ], + ]); + + static::assertContains('button-A', $out); + static::assertContains('button-B', $out); + static::assertContains('button-B', $out); + static::assertNotContains('button-C', $out); + } +}