Skip to content

Commit

Permalink
Fixes #2546: Added visible option to `yii\bootstrap\ButtonGroup::$b…
Browse files Browse the repository at this point in the history
…uttons`
  • Loading branch information
samdark committed Apr 12, 2015
1 parent 6fc0a43 commit 8e26e12
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ButtonGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace yii\bootstrap;

use yii\helpers\ArrayHelper;
use yii\helpers\Html;

/**
Expand All @@ -20,6 +21,7 @@
* 'buttons' => [
* ['label' => 'A'],
* ['label' => 'B'],
* ['label' => 'C', 'visible' => false],
* ]
* ]);
*
Expand All @@ -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 = [];
/**
Expand Down Expand Up @@ -80,6 +83,11 @@ protected function renderButtons()
$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;
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
29 changes: 29 additions & 0 deletions tests/ButtonGroupTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?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);
}
}

0 comments on commit 8e26e12

Please sign in to comment.