Commit 8e26e127 authored by Alexander Makarov's avatar Alexander Makarov

Fixes #2546: Added `visible` option to `yii\bootstrap\ButtonGroup::$buttons`

parent 6fc0a438
......@@ -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;
......
......@@ -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)
......
<?php
namespace yiiunit\extensions\bootstrap;
use yii\bootstrap\Button;
use yii\bootstrap\ButtonGroup;
/**
* @group bootstrap
*/
class ButtonGroupTest extends TestCase
{
public function testContainerOptions()
{
ButtonGroup::$counter = 0;
$out = ButtonGroup::widget([
'buttons' => [
['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);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment