Elgg
Version 1.11
Main Page
Related Pages
Namespaces
Classes
Files
Examples
File List
File Members
engine
classes
ElggMenuItem.php
Go to the documentation of this file.
1
<?php
15
class
ElggMenuItem
{
16
20
protected
$data
= array(
21
// string Identifier of the menu
22
'name'
=>
''
,
23
24
// array Page contexts this menu item should appear on
25
'contexts'
=> array(
'all'
),
26
27
// string Menu section identifier
28
'section'
=>
'default'
,
29
30
// int Smaller priorities float to the top
31
'priority'
=> 100,
32
33
// bool Is this the currently selected menu item
34
'selected'
=>
false
,
35
36
// string Identifier of this item's parent
37
'parent_name'
=>
''
,
38
39
// \ElggMenuItem The parent object or null
40
'parent'
=> null,
41
42
// array Array of children objects or empty array
43
'children'
=> array(),
44
45
// array Classes to apply to the li tag
46
'itemClass'
=> array(),
47
48
// array Classes to apply to the anchor tag
49
'linkClass'
=> array(),
50
);
51
55
protected
$text
;
56
60
protected
$href
= null;
61
65
protected
$title
=
false
;
66
70
protected
$confirm
=
''
;
71
72
80
public
function
__construct
(
$name
,
$text
,
$href
) {
81
$this->
text
=
$text
;
82
if
(
$href
) {
83
$this->href =
elgg_normalize_url
(
$href
);
84
}
else
{
85
$this->href =
$href
;
86
}
87
88
$this->data[
'name'
] =
$name
;
89
}
90
117
public
static
function
factory
(
$options
) {
118
if
(!isset(
$options
[
'name'
]) || !isset(
$options
[
'text'
])) {
119
return
null;
120
}
121
if
(!isset(
$options
[
'href'
])) {
122
$options
[
'href'
] =
''
;
123
}
124
125
$item
= new \ElggMenuItem(
$options
[
'name'
],
$options
[
'text'
],
$options
[
'href'
]);
126
unset(
$options
[
'name'
]);
127
unset(
$options
[
'text'
]);
128
unset(
$options
[
'href'
]);
129
130
// special catch in case someone uses context rather than contexts
131
if
(isset(
$options
[
'context'
])) {
132
$options
[
'contexts'
] =
$options
[
'context'
];
133
unset(
$options
[
'context'
]);
134
}
135
136
// make sure contexts is set correctly
137
if
(isset(
$options
[
'contexts'
])) {
138
$item
->setContext(
$options
[
'contexts'
]);
139
unset(
$options
[
'contexts'
]);
140
}
141
142
if
(isset(
$options
[
'link_class'
])) {
143
$item
->setLinkClass(
$options
[
'link_class'
]);
144
unset(
$options
[
'link_class'
]);
145
} elseif (isset(
$options
[
'class'
])) {
146
elgg_deprecated_notice
(
"\ElggMenuItem::factory() does not accept 'class' key anymore, use 'link_class' instead"
, 1.9);
147
$item
->setLinkClass(
$options
[
'class'
]);
148
unset(
$options
[
'class'
]);
149
}
150
151
if
(isset(
$options
[
'item_class'
])) {
152
$item
->setItemClass(
$options
[
'item_class'
]);
153
unset(
$options
[
'item_class'
]);
154
}
155
156
if
(isset(
$options
[
'data'
]) && is_array(
$options
[
'data'
])) {
157
$item
->setData(
$options
[
'data'
]);
158
unset(
$options
[
'data'
]);
159
}
160
161
foreach
(
$options
as
$key
=>
$value
) {
162
if
(isset(
$item
->data[
$key
])) {
163
$item
->data[
$key
] =
$value
;
164
}
else
{
165
$item
->$key =
$value
;
166
}
167
}
168
169
return
$item
;
170
}
171
182
public
function
setData
(
$key
,
$value
= null) {
183
if
(is_array(
$key
)) {
184
$this->data = array_merge($this->data,
$key
);
185
}
else
{
186
$this->data[
$key
] =
$value
;
187
}
188
}
189
196
public
function
getData
(
$key
) {
197
if
(isset($this->data[
$key
])) {
198
return
$this->data[
$key
];
199
}
else
{
200
return
null;
201
}
202
}
203
210
public
function
setName
(
$name
) {
211
$this->data[
'name'
] =
$name
;
212
}
213
219
public
function
getName
() {
220
return
$this->data[
'name'
];
221
}
222
229
public
function
setText
(
$text
) {
230
$this->
text
=
$text
;
231
}
232
238
public
function
getText
() {
239
return
$this->text
;
240
}
241
249
public
function
setHref
(
$href
) {
250
$this->href =
$href
;
251
}
252
258
public
function
getHref
() {
259
return
$this->href
;
260
}
261
268
public
function
setContext
(
$contexts
) {
269
if
(is_string(
$contexts
)) {
270
$contexts
= array(
$contexts
);
271
}
272
$this->data[
'contexts'
] =
$contexts
;
273
}
274
280
public
function
getContext
() {
281
return
$this->data[
'contexts'
];
282
}
283
291
public
function
inContext
(
$context
=
''
) {
292
if
(in_array(
'all'
, $this->data[
'contexts'
])) {
293
return
true
;
294
}
295
296
if
(
$context
) {
297
return
in_array(
$context
, $this->data[
'contexts'
]);
298
}
299
300
foreach
($this->data[
'contexts'
] as
$context
) {
301
if
(
elgg_in_context
($context)) {
302
return
true
;
303
}
304
}
305
return
false
;
306
}
307
314
public
function
setSelected
(
$state
=
true
) {
315
$this->data[
'selected'
] =
$state
;
316
}
317
323
public
function
getSelected
() {
324
return
$this->data[
'selected'
];
325
}
326
333
public
function
setTooltip
(
$text
) {
334
$this->
title
=
$text
;
335
}
336
342
public
function
getTooltip
() {
343
return
$this->title
;
344
}
345
352
public
function
setConfirmText
(
$text
) {
353
$this->confirm =
$text
;
354
}
355
361
public
function
getConfirmText
() {
362
return
$this->confirm
;
363
}
364
371
public
function
setLinkClass
(
$class
) {
372
if
(!is_array(
$class
)) {
373
$this->data[
'linkClass'
] = array(
$class
);
374
}
else
{
375
$this->data[
'linkClass'
] =
$class
;
376
}
377
}
378
384
public
function
getLinkClass
() {
385
return
implode(
' '
, $this->data[
'linkClass'
]);
386
}
387
394
public
function
addLinkClass
(
$class
) {
395
$this->
addClass
($this->data[
'linkClass'
],
$class
);
396
}
397
404
public
function
setItemClass
(
$class
) {
405
if
(!is_array(
$class
)) {
406
$this->data[
'itemClass'
] = array(
$class
);
407
}
else
{
408
$this->data[
'itemClass'
] =
$class
;
409
}
410
}
411
417
public
function
getItemClass
() {
418
// allow people to specify name with underscores and colons
419
$name
= strtolower($this->
getName
());
420
$name
= str_replace(
'_'
,
'-'
,
$name
);
421
$name
= str_replace(
':'
,
'-'
,
$name
);
422
$name
= str_replace(
' '
,
'-'
,
$name
);
423
424
$class
= implode(
' '
, $this->data[
'itemClass'
]);
425
if
(
$class
) {
426
return
"elgg-menu-item-$name $class"
;
427
}
else
{
428
return
"elgg-menu-item-$name"
;
429
}
430
}
431
439
public
function
addItemClass
(
$class
) {
440
$this->
addClass
($this->data[
'itemClass'
],
$class
);
441
}
442
443
// @codingStandardsIgnoreStart
451
protected
function
addClass
(array &$current, $additional) {
452
if
(!is_array($additional)) {
453
$current[] = $additional;
454
}
else
{
455
$current = array_merge($current, $additional);
456
}
457
}
458
// @codingStandardsIgnoreEnd
459
460
468
public
function
setWeight
(
$priority
) {
469
elgg_deprecated_notice
(
"\ElggMenuItem::setWeight() deprecated by \ElggMenuItem::setPriority()"
, 1.9);
470
$this->data[
'priority'
] =
$priority
;
471
}
472
479
public
function
getWeight
() {
480
elgg_deprecated_notice
(
"\ElggMenuItem::getWeight() deprecated by \ElggMenuItem::getPriority()"
, 1.9);
481
return
$this->data[
'priority'
];
482
}
483
490
public
function
setPriority
(
$priority
) {
491
$this->data[
'priority'
] =
$priority
;
492
}
493
499
public
function
getPriority
() {
500
return
$this->data[
'priority'
];
501
}
502
509
public
function
setSection
($section) {
510
$this->data[
'section'
] = $section;
511
}
512
518
public
function
getSection
() {
519
return
$this->data[
'section'
];
520
}
521
528
public
function
setParentName
(
$name
) {
529
$this->data[
'parent_name'
] =
$name
;
530
}
531
537
public
function
getParentName
() {
538
return
$this->data[
'parent_name'
];
539
}
540
550
public
function
setParent
($parent) {
551
$this->data[
'parent'
] = $parent;
552
}
553
562
public
function
getParent
() {
563
return
$this->data[
'parent'
];
564
}
565
575
public
function
addChild
(
$item
) {
576
$this->data[
'children'
][] =
$item
;
577
}
578
588
public
function
setChildren
(
$children
) {
589
$this->data[
'children'
] =
$children
;
590
}
591
600
public
function
getChildren
() {
601
return
$this->data[
'children'
];
602
}
603
613
public
function
sortChildren
($sortFunction) {
614
foreach
($this->data[
'children'
] as
$key
=> $node) {
615
$this->data[
'children'
][
$key
]->data[
'original_order'
] =
$key
;
616
}
617
usort($this->data[
'children'
], $sortFunction);
618
}
619
626
public
function
getValues
() {
627
$values = get_object_vars($this);
628
unset($values[
'data'
]);
629
630
return
$values;
631
}
632
640
public
function
getContent
(array
$vars
= array()) {
641
elgg_deprecated_notice
(
"\ElggMenuItem::getContent() deprecated by elgg_view_menu_item()"
, 1.9);
642
return
elgg_view_menu_item
($this,
$vars
);
643
}
644
}
title
ui datepicker title
Definition:
admin.php:616
$contexts
$contexts
Definition:
contents.php:13
$context
$context
Definition:
add.php:11
text
elgg input text
Definition:
admin.php:490
elgg_normalize_url
elgg_normalize_url($url)
Definition:
output.php:311
ElggMenuItem\$confirm
$confirm
Definition:
ElggMenuItem.php:70
ElggMenuItem\setParentName
setParentName($name)
Set the parent identifier.
Definition:
ElggMenuItem.php:528
$name
if($guid==elgg_get_logged_in_user_guid()) $name
Definition:
delete.php:21
ElggMenuItem\getItemClass
getItemClass()
Get the li classes as text.
Definition:
ElggMenuItem.php:417
ElggMenuItem\setText
setText($text)
Set the display text of the menu item.
Definition:
ElggMenuItem.php:229
ElggMenuItem\getData
getData($key)
Get stored data.
Definition:
ElggMenuItem.php:196
ElggMenuItem\setLinkClass
setLinkClass($class)
Set the anchor class.
Definition:
ElggMenuItem.php:371
ElggMenuItem\getChildren
getChildren()
Get the children menu items.
Definition:
ElggMenuItem.php:600
ElggMenuItem\setData
setData($key, $value=null)
Set a data key/value pair or a set of key/value pairs.
Definition:
ElggMenuItem.php:182
ElggMenuItem\getLinkClass
getLinkClass()
Get the anchor classes as text.
Definition:
ElggMenuItem.php:384
$value
$value
Definition:
longtext.php:26
ElggMenuItem\getContext
getContext()
Get an array of context strings.
Definition:
ElggMenuItem.php:280
ElggMenuItem\$title
$title
Definition:
ElggMenuItem.php:65
$class
if(isset($vars['id'])) $class
Definition:
ajax_loader.php:19
$state
$state
Definition:
contents.php:4
ElggMenuItem\$text
$text
Definition:
ElggMenuItem.php:55
ElggMenuItem\getContent
getContent(array $vars=array())
Get the menu item content (usually a link)
Definition:
ElggMenuItem.php:640
ElggMenuItem
Definition:
ElggMenuItem.php:15
ElggMenuItem\setChildren
setChildren($children)
Set the menu item's children.
Definition:
ElggMenuItem.php:588
$options
$options
Definition:
index.php:14
ElggMenuItem\factory
static factory($options)
Create an ElggMenuItem from an associative array.
Definition:
ElggMenuItem.php:117
ElggMenuItem\inContext
inContext($context= '')
Should this menu item be used given the current context.
Definition:
ElggMenuItem.php:291
ElggMenuItem\getConfirmText
getConfirmText()
Get the confirm text.
Definition:
ElggMenuItem.php:361
$key
$key
Definition:
summary.php:34
ElggMenuItem\getTooltip
getTooltip()
Get the tool tip text.
Definition:
ElggMenuItem.php:342
ElggMenuItem\setContext
setContext($contexts)
Set the contexts that this menu item is available for.
Definition:
ElggMenuItem.php:268
$item
$item
Definition:
item.php:12
ElggMenuItem\setItemClass
setItemClass($class)
Set the li classes.
Definition:
ElggMenuItem.php:404
ElggMenuItem\addItemClass
addItemClass($class)
Add a li class.
Definition:
ElggMenuItem.php:439
ElggMenuItem\addChild
addChild($item)
Add a child menu item.
Definition:
ElggMenuItem.php:575
elgg_in_context
elgg_in_context($context)
Check if this context exists anywhere in the stack.
Definition:
pageowner.php:250
ElggMenuItem\getSection
getSection()
Get the section identifier.
Definition:
ElggMenuItem.php:518
elgg_deprecated_notice
elgg_deprecated_notice($msg, $dep_version, $backtrace_level=1)
Log a notice about deprecated use of a function, view, etc.
Definition:
elgglib.php:1006
ElggMenuItem\getPriority
getPriority()
Get the priority of the menu item.
Definition:
ElggMenuItem.php:499
ElggMenuItem\setName
setName($name)
Set the identifier of the menu item.
Definition:
ElggMenuItem.php:210
ElggMenuItem\setParent
setParent($parent)
Set the parent menu item.
Definition:
ElggMenuItem.php:550
ElggMenuItem\setWeight
setWeight($priority)
Set the priority of the menu item.
Definition:
ElggMenuItem.php:468
ElggMenuItem\$href
$href
Definition:
ElggMenuItem.php:60
ElggMenuItem\setHref
setHref($href)
Set the URL of the menu item.
Definition:
ElggMenuItem.php:249
ElggMenuItem\setSelected
setSelected($state=true)
Set the selected flag.
Definition:
ElggMenuItem.php:314
ElggMenuItem\getText
getText()
Get the display text of the menu item.
Definition:
ElggMenuItem.php:238
ElggMenuItem\addClass
addClass(array &$current, $additional)
Add additional classes.
Definition:
ElggMenuItem.php:451
elgg_view_menu_item
elgg_view_menu_item(\ElggMenuItem $item, array $vars=array())
Render a menu item (usually as a link)
Definition:
views.php:733
ElggMenuItem\setConfirmText
setConfirmText($text)
Set the confirm text shown when link is clicked.
Definition:
ElggMenuItem.php:352
$children
if($item->getSelected()) $children
Definition:
item.php:21
ElggMenuItem\getName
getName()
Get the identifier of the menu item.
Definition:
ElggMenuItem.php:219
ElggMenuItem\setTooltip
setTooltip($text)
Set the tool tip text.
Definition:
ElggMenuItem.php:333
ElggMenuItem\sortChildren
sortChildren($sortFunction)
Sort the children.
Definition:
ElggMenuItem.php:613
ElggMenuItem\getSelected
getSelected()
Get selected state.
Definition:
ElggMenuItem.php:323
ElggMenuItem\getParent
getParent()
Get the parent menu item.
Definition:
ElggMenuItem.php:562
ElggMenuItem\setSection
setSection($section)
Set the section identifier.
Definition:
ElggMenuItem.php:509
ElggMenuItem\getWeight
getWeight()
Get the priority of the menu item.
Definition:
ElggMenuItem.php:479
ElggMenuItem\getParentName
getParentName()
Get the parent identifier.
Definition:
ElggMenuItem.php:537
$priority
$priority
Definition:
set_priority.php:17
ElggMenuItem\__construct
__construct($name, $text, $href)
constructor
Definition:
ElggMenuItem.php:80
ElggMenuItem\getValues
getValues()
Get all the values for this menu item.
Definition:
ElggMenuItem.php:626
ElggMenuItem\getHref
getHref()
Get the URL of the menu item.
Definition:
ElggMenuItem.php:258
ElggMenuItem\$data
$data
Definition:
ElggMenuItem.php:20
ElggMenuItem\setPriority
setPriority($priority)
Set the priority of the menu item.
Definition:
ElggMenuItem.php:490
$vars
if(file_exists($welcome)) $vars
Definition:
upgrade.php:93
ElggMenuItem\addLinkClass
addLinkClass($class)
Add a link class.
Definition:
ElggMenuItem.php:394
Generated on Sat Dec 21 2024 00:00:49 for Elgg by
1.8.11