|
|
@ -20,13 +20,15 @@ use yii\helpers\Html; |
|
|
|
* echo Collapse::widget([ |
|
|
|
* echo Collapse::widget([ |
|
|
|
* 'items' => [ |
|
|
|
* 'items' => [ |
|
|
|
* // equivalent to the above |
|
|
|
* // equivalent to the above |
|
|
|
* 'Collapsible Group Item #1' => [ |
|
|
|
* [ |
|
|
|
|
|
|
|
* 'label' => 'Collapsible Group Item #1', |
|
|
|
* 'content' => 'Anim pariatur cliche...', |
|
|
|
* 'content' => 'Anim pariatur cliche...', |
|
|
|
* // open its content by default |
|
|
|
* // open its content by default |
|
|
|
* 'contentOptions' => ['class' => 'in'] |
|
|
|
* 'contentOptions' => ['class' => 'in'] |
|
|
|
* ], |
|
|
|
* ], |
|
|
|
* // another group item |
|
|
|
* // another group item |
|
|
|
* 'Collapsible Group Item #2' => [ |
|
|
|
* [ |
|
|
|
|
|
|
|
* 'label' => 'Collapsible Group Item #1', |
|
|
|
* 'content' => 'Anim pariatur cliche...', |
|
|
|
* 'content' => 'Anim pariatur cliche...', |
|
|
|
* 'contentOptions' => [...], |
|
|
|
* 'contentOptions' => [...], |
|
|
|
* 'options' => [...], |
|
|
|
* 'options' => [...], |
|
|
@ -45,20 +47,22 @@ class Collapse extends Widget |
|
|
|
* @var array list of groups in the collapse widget. Each array element represents a single |
|
|
|
* @var array list of groups in the collapse widget. Each array element represents a single |
|
|
|
* group with the following structure: |
|
|
|
* group with the following structure: |
|
|
|
* |
|
|
|
* |
|
|
|
* ```php |
|
|
|
* - label: string, required, the group header label. |
|
|
|
* // item key is the actual group header |
|
|
|
* - encode: boolean, optional, whether this label should be HTML-encoded. This param will override |
|
|
|
* 'Collapsible Group Item #1' => [ |
|
|
|
* global `$this->encodeLabels` param. |
|
|
|
* // required, the content (HTML) of the group |
|
|
|
* - content: string, required, the content (HTML) of the group |
|
|
|
* 'content' => 'Anim pariatur cliche...', |
|
|
|
* - options: array, optional, the HTML attributes of the group |
|
|
|
* // optional the HTML attributes of the content group |
|
|
|
* - contentOptions: optional, the HTML attributes of the group's content |
|
|
|
* 'contentOptions' => [], |
|
|
|
* |
|
|
|
* // optional the HTML attributes of the group |
|
|
|
|
|
|
|
* 'options' => [], |
|
|
|
|
|
|
|
* ] |
|
|
|
|
|
|
|
* ``` |
|
|
|
* ``` |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public $items = []; |
|
|
|
public $items = []; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* @var boolean whether the labels for header items should be HTML-encoded. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public $encodeLabels = true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Initializes the widget. |
|
|
|
* Initializes the widget. |
|
|
@ -88,7 +92,11 @@ class Collapse extends Widget |
|
|
|
{ |
|
|
|
{ |
|
|
|
$items = []; |
|
|
|
$items = []; |
|
|
|
$index = 0; |
|
|
|
$index = 0; |
|
|
|
foreach ($this->items as $header => $item) { |
|
|
|
foreach ($this->items as $item) { |
|
|
|
|
|
|
|
if (!isset($item['label'])) { |
|
|
|
|
|
|
|
throw new InvalidConfigException("The 'label' option is required."); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
$header = $item['label']; |
|
|
|
$options = ArrayHelper::getValue($item, 'options', []); |
|
|
|
$options = ArrayHelper::getValue($item, 'options', []); |
|
|
|
Html::addCssClass($options, 'panel panel-default'); |
|
|
|
Html::addCssClass($options, 'panel panel-default'); |
|
|
|
$items[] = Html::tag('div', $this->renderItem($header, $item, ++$index), $options); |
|
|
|
$items[] = Html::tag('div', $this->renderItem($header, $item, ++$index), $options); |
|
|
@ -113,6 +121,11 @@ class Collapse extends Widget |
|
|
|
$options['id'] = $id; |
|
|
|
$options['id'] = $id; |
|
|
|
Html::addCssClass($options, 'panel-collapse collapse'); |
|
|
|
Html::addCssClass($options, 'panel-collapse collapse'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$encodeLabel = isset($item['encode']) ? $item['encode'] : $this->encodeLabels; |
|
|
|
|
|
|
|
if ($encodeLabel) { |
|
|
|
|
|
|
|
$header = Html::encode($header); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$headerToggle = Html::a($header, '#' . $id, [ |
|
|
|
$headerToggle = Html::a($header, '#' . $id, [ |
|
|
|
'class' => 'collapse-toggle', |
|
|
|
'class' => 'collapse-toggle', |
|
|
|
'data-toggle' => 'collapse', |
|
|
|
'data-toggle' => 'collapse', |
|
|
|