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
f387e6eb
Commit
f387e6eb
authored
May 15, 2015
by
Klimov Paul
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added `submenuOptions` support at `yii\bootstrap\Dropdown`
parent
63ddbe87
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
4 deletions
+61
-4
CHANGELOG.md
CHANGELOG.md
+1
-0
Dropdown.php
Dropdown.php
+19
-3
DropdownTest.php
tests/DropdownTest.php
+41
-1
No files found.
CHANGELOG.md
View file @
f387e6eb
...
@@ -6,6 +6,7 @@ Yii Framework 2 bootstrap extension Change Log
...
@@ -6,6 +6,7 @@ Yii Framework 2 bootstrap extension Change Log
-
Enh #38: Added object support for
`content`
option in
`Collapse`
class (pana1990, ItsReddi)
-
Enh #38: Added object support for
`content`
option in
`Collapse`
class (pana1990, ItsReddi)
-
Enh #40: Added
`visible`
option to
`yii\bootstrap\Tab`
widget items (klimov-paul)
-
Enh #40: Added
`visible`
option to
`yii\bootstrap\Tab`
widget items (klimov-paul)
-
Enh #41: Added
`submenuOptions`
support at
`yii\bootstrap\Dropdown`
(spikyjt, klimov-paul)
2.
0.4 May 10, 2015
2.
0.4 May 10, 2015
------------------
------------------
...
...
Dropdown.php
View file @
f387e6eb
...
@@ -48,6 +48,8 @@ class Dropdown extends Widget
...
@@ -48,6 +48,8 @@ class Dropdown extends Widget
* - options: array, optional, the HTML attributes of the item.
* - options: array, optional, the HTML attributes of the item.
* - items: array, optional, the submenu items. The structure is the same as this property.
* - items: array, optional, the submenu items. The structure is the same as this property.
* Note that Bootstrap doesn't support dropdown submenu. You have to add your own CSS styles to support it.
* Note that Bootstrap doesn't support dropdown submenu. You have to add your own CSS styles to support it.
* - submenuOptions: array, optional, the HTML attributes for sub-menu container tag. If specified it will be
* merged with [[submenuOptions]].
*
*
* To insert divider use `<li role="presentation" class="divider"></li>`.
* To insert divider use `<li role="presentation" class="divider"></li>`.
*/
*/
...
@@ -56,6 +58,12 @@ class Dropdown extends Widget
...
@@ -56,6 +58,12 @@ class Dropdown extends Widget
* @var boolean whether the labels for header items should be HTML-encoded.
* @var boolean whether the labels for header items should be HTML-encoded.
*/
*/
public
$encodeLabels
=
true
;
public
$encodeLabels
=
true
;
/**
* @var array|null the HTML attributes for sub-menu container tags.
* If not set - [[options]] value will be used for it.
* @since 2.0.5
*/
public
$submenuOptions
;
/**
/**
...
@@ -64,6 +72,12 @@ class Dropdown extends Widget
...
@@ -64,6 +72,12 @@ class Dropdown extends Widget
*/
*/
public
function
init
()
public
function
init
()
{
{
if
(
$this
->
submenuOptions
===
null
)
{
// copying of [[options]] kept for BC
// @todo separate [[submenuOptions]] from [[options]] completely before 2.1 release
$this
->
submenuOptions
=
$this
->
options
;
unset
(
$this
->
submenuOptions
[
'id'
]);
}
parent
::
init
();
parent
::
init
();
Html
::
addCssClass
(
$this
->
options
,
'dropdown-menu'
);
Html
::
addCssClass
(
$this
->
options
,
'dropdown-menu'
);
}
}
...
@@ -88,7 +102,7 @@ class Dropdown extends Widget
...
@@ -88,7 +102,7 @@ class Dropdown extends Widget
protected
function
renderItems
(
$items
,
$options
=
[])
protected
function
renderItems
(
$items
,
$options
=
[])
{
{
$lines
=
[];
$lines
=
[];
foreach
(
$items
as
$i
=>
$i
tem
)
{
foreach
(
$items
as
$item
)
{
if
(
isset
(
$item
[
'visible'
])
&&
!
$item
[
'visible'
])
{
if
(
isset
(
$item
[
'visible'
])
&&
!
$item
[
'visible'
])
{
continue
;
continue
;
}
}
...
@@ -113,8 +127,10 @@ class Dropdown extends Widget
...
@@ -113,8 +127,10 @@ class Dropdown extends Widget
$content
=
Html
::
a
(
$label
,
$url
,
$linkOptions
);
$content
=
Html
::
a
(
$label
,
$url
,
$linkOptions
);
}
}
}
else
{
}
else
{
$submenuOptions
=
$options
;
$submenuOptions
=
$this
->
submenuOptions
;
unset
(
$submenuOptions
[
'id'
]);
if
(
isset
(
$item
[
'submenuOptions'
]))
{
$submenuOptions
=
array_merge
(
$submenuOptions
,
$item
[
'submenuOptions'
]);
}
$content
=
Html
::
a
(
$label
,
$url
===
null
?
'#'
:
$url
,
$linkOptions
)
$content
=
Html
::
a
(
$label
,
$url
===
null
?
'#'
:
$url
,
$linkOptions
)
.
$this
->
renderItems
(
$item
[
'items'
],
$submenuOptions
);
.
$this
->
renderItems
(
$item
[
'items'
],
$submenuOptions
);
Html
::
addCssClass
(
$itemOptions
,
'dropdown-submenu'
);
Html
::
addCssClass
(
$itemOptions
,
'dropdown-submenu'
);
...
...
tests/DropdownTest.php
View file @
f387e6eb
...
@@ -41,8 +41,48 @@ class DropdownTest extends TestCase
...
@@ -41,8 +41,48 @@ class DropdownTest extends TestCase
$expected
=
<<<EXPECTED
$expected
=
<<<EXPECTED
<ul id="w0" class="dropdown-menu"><li class="dropdown-header">Page1</li>
<ul id="w0" class="dropdown-menu"><li class="dropdown-header">Page1</li>
<li class="dropdown-submenu"><a href="#" tabindex="-1">Dropdown1</a><ul
class="dropdown-menu"
><li class="dropdown-header">Page2</li>
<li class="dropdown-submenu"><a href="#" tabindex="-1">Dropdown1</a><ul><li class="dropdown-header">Page2</li>
<li class="dropdown-header">Page3</li></ul></li></ul>
<li class="dropdown-header">Page3</li></ul></li></ul>
EXPECTED;
$this
->
assertEqualsWithoutLE
(
$expected
,
$out
);
}
public
function
testSubMenuOptions
()
{
Dropdown
::
$counter
=
0
;
$out
=
Dropdown
::
widget
(
[
'submenuOptions'
=>
[
'class'
=>
'submenu-list'
,
],
'items'
=>
[
[
'label'
=>
'Dropdown1'
,
'items'
=>
[
[
'label'
=>
'Page1'
,
'content'
=>
'Page2'
],
[
'label'
=>
'Page2'
,
'content'
=>
'Page3'
],
]
],
[
'label'
=>
'Dropdown2'
,
'items'
=>
[
[
'label'
=>
'Page3'
,
'content'
=>
'Page4'
],
[
'label'
=>
'Page4'
,
'content'
=>
'Page5'
],
],
'submenuOptions'
=>
[
'class'
=>
'submenu-override'
,
],
]
]
]
);
$expected
=
<<<EXPECTED
<ul id="w0" class="dropdown-menu"><li class="dropdown-submenu"><a href="#" tabindex="-1">Dropdown1</a><ul class="submenu-list"><li class="dropdown-header">Page1</li>
<li class="dropdown-header">Page2</li></ul></li>
<li class="dropdown-submenu"><a href="#" tabindex="-1">Dropdown2</a><ul class="submenu-override"><li class="dropdown-header">Page3</li>
<li class="dropdown-header">Page4</li></ul></li></ul>
EXPECTED;
EXPECTED;
$this
->
assertEqualsWithoutLE
(
$expected
,
$out
);
$this
->
assertEqualsWithoutLE
(
$expected
,
$out
);
...
...
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