From a22b4f6b1b0bb77ebac0e7eefb52514bffa00937 Mon Sep 17 00:00:00 2001 From: freezy Date: Thu, 6 Aug 2015 17:14:58 +0200 Subject: [PATCH] Added option to define custom options for list of items when content is array --- Collapse.php | 6 ++++-- tests/CollapseTest.php | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Collapse.php b/Collapse.php index b2de61fc3..67f39e0c2 100644 --- a/Collapse.php +++ b/Collapse.php @@ -63,6 +63,7 @@ class Collapse extends Widget * - content: array|string|object, required, the content (HTML) of the group * - options: array, optional, the HTML attributes of the group * - contentOptions: optional, the HTML attributes of the group's content + * - contentListOptions: optional, options merged with default and passed to `Html::ul` when content is array */ public $items = []; @@ -148,13 +149,14 @@ public function renderItem($header, $item, $index) if (is_string($item['content']) || is_object($item['content'])) { $content = Html::tag('div', $item['content'], ['class' => 'panel-body']) . "\n"; } elseif (is_array($item['content'])) { - $content = Html::ul($item['content'], [ + $contentListOptions = ArrayHelper::merge([ 'class' => 'list-group', 'itemOptions' => [ 'class' => 'list-group-item' ], 'encode' => false, - ]) . "\n"; + ], ArrayHelper::getValue($item, 'contentListOptions', [])); + $content = Html::ul($item['content'], $contentListOptions) . "\n"; if (isset($item['footer'])) { $content .= Html::tag('div', $item['footer'], ['class' => 'panel-footer']) . "\n"; } diff --git a/tests/CollapseTest.php b/tests/CollapseTest.php index aa703bcca..ea896e6af 100644 --- a/tests/CollapseTest.php +++ b/tests/CollapseTest.php @@ -67,6 +67,17 @@ public function testRender() 'encode' => true, 'footer' => 'Footer3' ], + [ + 'label' => '

Collapsible Group Item #5

', + 'content' => [ + '

test content1

', + '

test content2

' + ], + 'contentListOptions' => [ + 'class' => 'list-group list-group-custom', + 'encode' => true, + ], + ], ] ]); @@ -103,6 +114,13 @@ public function testRender() +
+
    +
  • <h2>test content1</h2>
  • +
  • <h2>test content2</h2>
  • +
+
HTML