Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Y
yii2bootstrap
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
夏彬
yii2bootstrap
Commits
f7cc408d
Commit
f7cc408d
authored
May 11, 2015
by
pana1990
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix 29: Added support to object for content option in Collapse class
parent
551a391d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
66 additions
and
4 deletions
+66
-4
CHANGELOG.md
CHANGELOG.md
+1
-1
Collapse.php
Collapse.php
+3
-3
CollapseTest.php
tests/CollapseTest.php
+35
-0
Singer.php
tests/data/Singer.php
+27
-0
No files found.
CHANGELOG.md
View file @
f7cc408d
...
@@ -4,7 +4,7 @@ Yii Framework 2 bootstrap extension Change Log
...
@@ -4,7 +4,7 @@ Yii Framework 2 bootstrap extension Change Log
2.
0.5 under development
2.
0.5 under development
-----------------------
-----------------------
-
Enh #38: Added support to object for content option in Collapse class (pana1990, ItsReddi)
2.
0.4 May 10, 2015
2.
0.4 May 10, 2015
------------------
------------------
...
...
Collapse.php
View file @
f7cc408d
...
@@ -61,7 +61,7 @@ class Collapse extends Widget
...
@@ -61,7 +61,7 @@ class Collapse extends Widget
* - label: string, required, the group header label.
* - label: string, required, the group header label.
* - encode: boolean, optional, whether this label should be HTML-encoded. This param will override
* - encode: boolean, optional, whether this label should be HTML-encoded. This param will override
* global `$this->encodeLabels` param.
* global `$this->encodeLabels` param.
* - content: array|string, required, the content (HTML) of the group
* - content: array|string
|object
, required, the content (HTML) of the group
* - options: array, optional, the HTML attributes of the group
* - options: array, optional, the HTML attributes of the group
* - contentOptions: optional, the HTML attributes of the group's content
* - contentOptions: optional, the HTML attributes of the group's content
*/
*/
...
@@ -146,7 +146,7 @@ class Collapse extends Widget
...
@@ -146,7 +146,7 @@ class Collapse extends Widget
$header
=
Html
::
tag
(
'h4'
,
$headerToggle
,
[
'class'
=>
'panel-title'
]);
$header
=
Html
::
tag
(
'h4'
,
$headerToggle
,
[
'class'
=>
'panel-title'
]);
if
(
is_string
(
$item
[
'content'
]))
{
if
(
is_string
(
$item
[
'content'
])
||
is_object
(
$item
[
'content'
])
)
{
$content
=
Html
::
tag
(
'div'
,
$item
[
'content'
],
[
'class'
=>
'panel-body'
])
.
"
\n
"
;
$content
=
Html
::
tag
(
'div'
,
$item
[
'content'
],
[
'class'
=>
'panel-body'
])
.
"
\n
"
;
}
elseif
(
is_array
(
$item
[
'content'
]))
{
}
elseif
(
is_array
(
$item
[
'content'
]))
{
$content
=
Html
::
ul
(
$item
[
'content'
],
[
$content
=
Html
::
ul
(
$item
[
'content'
],
[
...
@@ -160,7 +160,7 @@ class Collapse extends Widget
...
@@ -160,7 +160,7 @@ class Collapse extends Widget
$content
.=
Html
::
tag
(
'div'
,
$item
[
'footer'
],
[
'class'
=>
'panel-footer'
])
.
"
\n
"
;
$content
.=
Html
::
tag
(
'div'
,
$item
[
'footer'
],
[
'class'
=>
'panel-footer'
])
.
"
\n
"
;
}
}
}
else
{
}
else
{
throw
new
InvalidConfigException
(
'The "content" option should be a string
or array
.'
);
throw
new
InvalidConfigException
(
'The "content" option should be a string
, array or object
.'
);
}
}
}
else
{
}
else
{
throw
new
InvalidConfigException
(
'The "content" option is required.'
);
throw
new
InvalidConfigException
(
'The "content" option is required.'
);
...
...
tests/CollapseTest.php
View file @
f7cc408d
...
@@ -105,6 +105,41 @@ class CollapseTest extends TestCase
...
@@ -105,6 +105,41 @@ class CollapseTest extends TestCase
</div></div>
</div></div>
</div>
</div>
HTML
,
$output
);
}
/**
* @see https://github.com/yiisoft/yii2/issues/8357
*/
public
function
testRenderObject
()
{
$template
=
[
'template'
=>
'{input}'
];
ob_start
();
$form
=
\yii\widgets\ActiveForm
::
begin
([
'action'
=>
'/something'
]);
ob_end_clean
();
$model
=
new
data\Singer
;
Collapse
::
$counter
=
0
;
$output
=
Collapse
::
widget
([
'items'
=>
[
[
'label'
=>
'Collapsible Group Item #1'
,
'content'
=>
$form
->
field
(
$model
,
'firstName'
,
$template
)
],
]
]);
$this
->
assertEqualsWithoutLE
(
<<<HTML
<div id="w0" class="panel-group">
<div class="panel panel-default"><div class="panel-heading"><h4 class="panel-title"><a class="collapse-toggle" href="#w0-collapse1" data-toggle="collapse" data-parent="#w0">Collapsible Group Item #1</a>
</h4></div>
<div id="w0-collapse1" class="panel-collapse collapse"><div class="panel-body"><div class="form-group field-singer-firstname">
<input type="text" id="singer-firstname" class="form-control" name="Singer[firstName]">
</div></div>
</div></div>
</div>
HTML
HTML
,
$output
);
,
$output
);
}
}
...
...
tests/data/Singer.php
0 → 100644
View file @
f7cc408d
<?php
namespace
yiiunit\extensions\bootstrap\data
;
use
yii\base\Model
;
/**
* Class Singer
*
* @author Daniel Gomez Pan <pana_1990@hotmail.com>
*/
class
Singer
extends
Model
{
public
$firstName
;
public
$lastName
;
public
$test
;
public
function
rules
()
{
return
[
[[
'lastName'
],
'default'
,
'value'
=>
'Lennon'
],
[[
'lastName'
],
'required'
],
[[
'underscore_style'
],
'yii\captcha\CaptchaValidator'
],
[[
'test'
],
'required'
,
'when'
=>
function
(
$model
)
{
return
$model
->
firstName
===
'cebe'
;
}],
];
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment