Skip to content

for Collapse, tabs and other widgets that require label, let the key on the $items property be the label by default #64

@Faryshta

Description

@Faryshta

For example:

echo Collapse::widget([
    'items' => [
        'Introduction' => 'This is the first collapsable menu',
        'Second panel' => [
            'content' => 'This is the second collapsable menu',
        ],
    ]   
])

would be the equivalent of

echo Collapse::widget([
    'items' => [
        [
            'label' => 'Introduction',
            'content' => 'This is the first collapsable menu',
        ],
        [
            'lable' => 'Second panel',
            'content' => 'This is the second collapsable menu',
        ],
    ]   
])

The patch is actually very simple, for example for the Tabs widget you only need to change the lines https://github.com/yiisoft/yii2-bootstrap/blob/master/Tabs.php#L155-159 to

            if (!is_string($key) && !array_key_exists('label', $item)) {
                throw new InvalidConfigException(
                    "The 'label' option is required."
                );
            }
            if (is_string($item)) {
                $item = ['content' => $item];
            }

            $label = is_string($key) ? $key : $item['label'];
            $encodeLabel = isset($item['encode'])
                ? $item['encode']
                : $this->encodeLabels;
            $label = $encodeLabel
                ? Html::encode($label)
                : $label;

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions