Browse Source

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

tags/2.0.4
Alexander Makarov 10 years ago
parent
commit
8e26e12744
  1. 8
      ButtonGroup.php
  2. 1
      CHANGELOG.md
  3. 29
      tests/ButtonGroupTest.php

8
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;

1
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)

29
tests/ButtonGroupTest.php

@ -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);
}
}
Loading…
Cancel
Save