Elgg
Version 2.3
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
// array AMD modules required by this menu item
52
'deps'
=> array()
53
);
54
58
protected
$text
;
59
63
protected
$href
= null;
64
68
protected
$title
=
false
;
69
73
protected
$confirm
=
''
;
74
75
83
public
function
__construct
(
$name
,
$text
,
$href
) {
84
$this->
text
=
$text
;
85
if
(
$href
) {
86
$this->href =
elgg_normalize_url
(
$href
);
87
}
else
{
88
$this->href =
$href
;
89
}
90
91
$this->data[
'name'
] =
$name
;
92
}
93
125
public
static
function
factory
(
$options
) {
126
if
(!isset(
$options
[
'name'
]) || !isset(
$options
[
'text'
])) {
127
elgg_log
(__METHOD__ .
': $options "name" and "text" are required.'
,
'ERROR'
);
128
return
null;
129
}
130
if
(!isset(
$options
[
'href'
])) {
131
$options
[
'href'
] =
''
;
132
}
133
134
$item
= new \ElggMenuItem(
$options
[
'name'
],
$options
[
'text'
],
$options
[
'href'
]);
135
unset(
$options
[
'name'
]);
136
unset(
$options
[
'text'
]);
137
unset(
$options
[
'href'
]);
138
139
// special catch in case someone uses context rather than contexts
140
if
(isset(
$options
[
'context'
])) {
141
$options
[
'contexts'
] =
$options
[
'context'
];
142
unset(
$options
[
'context'
]);
143
}
144
145
// make sure contexts is set correctly
146
if
(isset(
$options
[
'contexts'
])) {
147
$item
->setContext(
$options
[
'contexts'
]);
148
unset(
$options
[
'contexts'
]);
149
}
150
151
if
(isset(
$options
[
'link_class'
])) {
152
$item
->setLinkClass(
$options
[
'link_class'
]);
153
unset(
$options
[
'link_class'
]);
154
} elseif (isset(
$options
[
'class'
])) {
155
elgg_deprecated_notice
(
"\ElggMenuItem::factory() does not accept 'class' key anymore, use 'link_class' instead"
, 1.9);
156
$item
->setLinkClass(
$options
[
'class'
]);
157
unset(
$options
[
'class'
]);
158
}
159
160
if
(isset(
$options
[
'item_class'
])) {
161
$item
->setItemClass(
$options
[
'item_class'
]);
162
unset(
$options
[
'item_class'
]);
163
}
164
165
if
(isset(
$options
[
'data'
]) && is_array(
$options
[
'data'
])) {
166
$item
->setData(
$options
[
'data'
]);
167
unset(
$options
[
'data'
]);
168
}
169
170
foreach
(
$options
as
$key
=>
$value
) {
171
if
(isset(
$item
->data[
$key
])) {
172
$item
->data[
$key
] =
$value
;
173
}
else
{
174
$item
->$key =
$value
;
175
}
176
}
177
178
return
$item
;
179
}
180
191
public
function
setData
(
$key
,
$value
= null) {
192
if
(is_array(
$key
)) {
193
$this->data = array_merge($this->data,
$key
);
194
}
else
{
195
$this->data[
$key
] =
$value
;
196
}
197
}
198
205
public
function
getData
(
$key
) {
206
if
(isset($this->data[
$key
])) {
207
return
$this->data[
$key
];
208
}
else
{
209
return
null;
210
}
211
}
212
219
public
function
setName
(
$name
) {
220
$this->data[
'name'
] =
$name
;
221
}
222
228
public
function
getName
() {
229
return
$this->data[
'name'
];
230
}
231
238
public
function
setText
(
$text
) {
239
$this->
text
=
$text
;
240
}
241
247
public
function
getText
() {
248
return
$this->text
;
249
}
250
258
public
function
setHref
(
$href
) {
259
$this->href =
$href
;
260
}
261
267
public
function
getHref
() {
268
return
$this->href
;
269
}
270
277
public
function
setContext
(
$contexts
) {
278
if
(is_string(
$contexts
)) {
279
$contexts
= array(
$contexts
);
280
}
281
$this->data[
'contexts'
] =
$contexts
;
282
}
283
289
public
function
getContext
() {
290
return
$this->data[
'contexts'
];
291
}
292
300
public
function
inContext
(
$context
=
''
) {
301
if
(in_array(
'all'
, $this->data[
'contexts'
])) {
302
return
true
;
303
}
304
305
if
(
$context
) {
306
return
in_array(
$context
, $this->data[
'contexts'
]);
307
}
308
309
foreach
($this->data[
'contexts'
] as
$context
) {
310
if
(
elgg_in_context
($context)) {
311
return
true
;
312
}
313
}
314
return
false
;
315
}
316
323
public
function
setSelected
(
$state
=
true
) {
324
$this->data[
'selected'
] =
$state
;
325
}
326
332
public
function
getSelected
() {
333
return
$this->data[
'selected'
];
334
}
335
342
public
function
setTooltip
(
$text
) {
343
$this->
title
=
$text
;
344
}
345
351
public
function
getTooltip
() {
352
return
$this->title
;
353
}
354
361
public
function
setConfirmText
(
$text
) {
362
$this->confirm =
$text
;
363
}
364
370
public
function
getConfirmText
() {
371
return
$this->confirm
;
372
}
373
380
public
function
setLinkClass
(
$class
) {
381
if
(!is_array(
$class
)) {
382
$this->data[
'linkClass'
] = array(
$class
);
383
}
else
{
384
$this->data[
'linkClass'
] =
$class
;
385
}
386
}
387
393
public
function
getLinkClass
() {
394
return
implode(
' '
, $this->data[
'linkClass'
]);
395
}
396
403
public
function
addLinkClass
(
$class
) {
404
$this->
addClass
($this->data[
'linkClass'
],
$class
);
405
}
406
413
public
function
setDeps
(
$modules
) {
414
$this->data[
'deps'
] = (array)
$modules
;
415
}
416
422
public
function
getDeps
() {
423
$modules
= (array) $this->data[
'deps'
];
424
return
array_filter(
$modules
,
function
(
$m
) {
425
return
is_string(
$m
) && !empty(
$m
);
426
});
427
}
428
435
public
function
addDeps
(
$modules
) {
436
$current = $this->
getDeps
();
437
$this->
setDeps
($current + (array)
$modules
);
438
}
439
446
public
function
setItemClass
(
$class
) {
447
if
(!is_array(
$class
)) {
448
$this->data[
'itemClass'
] = array(
$class
);
449
}
else
{
450
$this->data[
'itemClass'
] =
$class
;
451
}
452
}
453
459
public
function
getItemClass
() {
460
// allow people to specify name with underscores and colons
461
$name
= strtolower($this->
getName
());
462
$name
= str_replace(
'_'
,
'-'
,
$name
);
463
$name
= str_replace(
':'
,
'-'
,
$name
);
464
$name
= str_replace(
' '
,
'-'
,
$name
);
465
466
$class
= implode(
' '
, $this->data[
'itemClass'
]);
467
if
(
$class
) {
468
return
"elgg-menu-item-$name $class"
;
469
}
else
{
470
return
"elgg-menu-item-$name"
;
471
}
472
}
473
481
public
function
addItemClass
(
$class
) {
482
$this->
addClass
($this->data[
'itemClass'
],
$class
);
483
}
484
485
// @codingStandardsIgnoreStart
493
protected
function
addClass
(array &$current, $additional) {
494
if
(!is_array($additional)) {
495
$current[] = $additional;
496
}
else
{
497
$current = array_merge($current, $additional);
498
}
499
}
500
// @codingStandardsIgnoreEnd
501
502
510
public
function
setWeight
(
$priority
) {
511
elgg_deprecated_notice
(
"\ElggMenuItem::setWeight() deprecated by \ElggMenuItem::setPriority()"
, 1.9);
512
$this->data[
'priority'
] =
$priority
;
513
}
514
521
public
function
getWeight
() {
522
elgg_deprecated_notice
(
"\ElggMenuItem::getWeight() deprecated by \ElggMenuItem::getPriority()"
, 1.9);
523
return
$this->data[
'priority'
];
524
}
525
532
public
function
setPriority
(
$priority
) {
533
$this->data[
'priority'
] =
$priority
;
534
}
535
541
public
function
getPriority
() {
542
return
$this->data[
'priority'
];
543
}
544
551
public
function
setSection
($section) {
552
$this->data[
'section'
] = $section;
553
}
554
560
public
function
getSection
() {
561
return
$this->data[
'section'
];
562
}
563
570
public
function
setParentName
(
$name
) {
571
$this->data[
'parent_name'
] =
$name
;
572
}
573
579
public
function
getParentName
() {
580
return
$this->data[
'parent_name'
];
581
}
582
592
public
function
setParent
($parent) {
593
$this->data[
'parent'
] = $parent;
594
}
595
604
public
function
getParent
() {
605
return
$this->data[
'parent'
];
606
}
607
617
public
function
addChild
(
$item
) {
618
$this->data[
'children'
][] =
$item
;
619
}
620
630
public
function
setChildren
(
$children
) {
631
$this->data[
'children'
] =
$children
;
632
}
633
642
public
function
getChildren
() {
643
return
$this->data[
'children'
];
644
}
645
655
public
function
sortChildren
($sortFunction) {
656
foreach
($this->data[
'children'
] as
$key
=> $node) {
657
$this->data[
'children'
][
$key
]->data[
'original_order'
] =
$key
;
658
}
659
usort($this->data[
'children'
], $sortFunction);
660
}
661
668
public
function
getValues
() {
669
$values = get_object_vars($this);
670
unset($values[
'data'
]);
671
672
return
$values;
673
}
674
682
public
function
getContent
(array
$vars
= array()) {
683
elgg_deprecated_notice
(
"\ElggMenuItem::getContent() deprecated by elgg_view_menu_item()"
, 1.9);
684
return
elgg_view_menu_item
($this,
$vars
);
685
}
686
}
$modules
$modules
Boot all the plugins and trigger the [init, system] hook.
Definition:
init.js.php:8
$contexts
$contexts
Definition:
contents.php:13
$context
$context
Definition:
add.php:11
$m
$m
Definition:
metadata.php:11
elgg_normalize_url
elgg_normalize_url($url)
Definition:
output.php:280
ElggMenuItem\$confirm
$confirm
Definition:
ElggMenuItem.php:73
ElggMenuItem\setParentName
setParentName($name)
Set the parent identifier.
Definition:
ElggMenuItem.php:570
$item
if(!$items) $item
Definition:
delete.php:17
$name
if($guid==elgg_get_logged_in_user_guid()) $name
Definition:
delete.php:21
ElggMenuItem
ElggMenuItem\getItemClass
getItemClass()
Get the li classes as text.
Definition:
ElggMenuItem.php:459
ElggMenuItem\setText
setText($text)
Set the display text of the menu item.
Definition:
ElggMenuItem.php:238
ElggMenuItem\getData
getData($key)
Get stored data.
Definition:
ElggMenuItem.php:205
ElggMenuItem\setLinkClass
setLinkClass($class)
Set the anchor class.
Definition:
ElggMenuItem.php:380
ElggMenuItem\addDeps
addDeps($modules)
Add required AMD modules.
Definition:
ElggMenuItem.php:435
ElggMenuItem\getChildren
getChildren()
Get the children menu items.
Definition:
ElggMenuItem.php:642
ElggMenuItem\setData
setData($key, $value=null)
Set a data key/value pair or a set of key/value pairs.
Definition:
ElggMenuItem.php:191
ElggMenuItem\getLinkClass
getLinkClass()
Get the anchor classes as text.
Definition:
ElggMenuItem.php:393
$value
$value
Definition:
longtext.php:42
ElggMenuItem\getContext
getContext()
Get an array of context strings.
Definition:
ElggMenuItem.php:289
$class
$class
Definition:
field.php:20
ElggMenuItem\$title
$title
Definition:
ElggMenuItem.php:68
$vars
$vars['entity']
Definition:
plugin_settings.php:15
$state
$state
Definition:
contents.php:4
ElggMenuItem\$text
$text
Definition:
ElggMenuItem.php:58
$options
$options
Elgg admin footer.
Definition:
footer.php:6
ElggMenuItem\getContent
getContent(array $vars=array())
Get the menu item content (usually a link)
Definition:
ElggMenuItem.php:682
ElggMenuItem\setChildren
setChildren($children)
Set the menu item's children.
Definition:
ElggMenuItem.php:630
ElggMenuItem\factory
static factory($options)
Create an ElggMenuItem from an associative array.
Definition:
ElggMenuItem.php:125
title
ui datepicker title
Definition:
admin.css.php:662
ElggMenuItem\inContext
inContext($context= '')
Should this menu item be used given the current context.
Definition:
ElggMenuItem.php:300
ElggMenuItem\getConfirmText
getConfirmText()
Get the confirm text.
Definition:
ElggMenuItem.php:370
$key
$key
Definition:
summary.php:34
ElggMenuItem\getTooltip
getTooltip()
Get the tool tip text.
Definition:
ElggMenuItem.php:351
ElggMenuItem\setContext
setContext($contexts)
Set the contexts that this menu item is available for.
Definition:
ElggMenuItem.php:277
ElggMenuItem\setItemClass
setItemClass($class)
Set the li classes.
Definition:
ElggMenuItem.php:446
ElggMenuItem\addItemClass
addItemClass($class)
Add a li class.
Definition:
ElggMenuItem.php:481
ElggMenuItem\addChild
addChild($item)
Add a child menu item.
Definition:
ElggMenuItem.php:617
elgg_in_context
elgg_in_context($context)
Check if this context exists anywhere in the stack.
Definition:
pageowner.php:241
ElggMenuItem\getSection
getSection()
Get the section identifier.
Definition:
ElggMenuItem.php:560
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:1098
ElggMenuItem\getPriority
getPriority()
Get the priority of the menu item.
Definition:
ElggMenuItem.php:541
elgg_view_menu_item
elgg_view_menu_item(\ElggMenuItem $item, array $vars=array())
Render a menu item (usually as a link)
Definition:
views.php:815
ElggMenuItem\setName
setName($name)
Set the identifier of the menu item.
Definition:
ElggMenuItem.php:219
ElggMenuItem\setParent
setParent($parent)
Set the parent menu item.
Definition:
ElggMenuItem.php:592
ElggMenuItem\setWeight
setWeight($priority)
Set the priority of the menu item.
Definition:
ElggMenuItem.php:510
ElggMenuItem\$href
$href
Definition:
ElggMenuItem.php:63
ElggMenuItem\setHref
setHref($href)
Set the URL of the menu item.
Definition:
ElggMenuItem.php:258
ElggMenuItem\setSelected
setSelected($state=true)
Set the selected flag.
Definition:
ElggMenuItem.php:323
ElggMenuItem\getText
getText()
Get the display text of the menu item.
Definition:
ElggMenuItem.php:247
elgg_log
elgg_log($message, $level= 'NOTICE')
Display or log a message.
Definition:
elgglib.php:1028
text
elgg input text
Definition:
admin.css.php:505
ElggMenuItem\addClass
addClass(array &$current, $additional)
Add additional classes.
Definition:
ElggMenuItem.php:493
ElggMenuItem\setConfirmText
setConfirmText($text)
Set the confirm text shown when link is clicked.
Definition:
ElggMenuItem.php:361
$children
if($item->getSelected()) $children
Definition:
item.php:21
ElggMenuItem\getName
getName()
Get the identifier of the menu item.
Definition:
ElggMenuItem.php:228
ElggMenuItem\setTooltip
setTooltip($text)
Set the tool tip text.
Definition:
ElggMenuItem.php:342
ElggMenuItem\getDeps
getDeps()
Get required AMD modules.
Definition:
ElggMenuItem.php:422
ElggMenuItem\sortChildren
sortChildren($sortFunction)
Sort the children.
Definition:
ElggMenuItem.php:655
ElggMenuItem\getSelected
getSelected()
Get selected state.
Definition:
ElggMenuItem.php:332
ElggMenuItem\getParent
getParent()
Get the parent menu item.
Definition:
ElggMenuItem.php:604
ElggMenuItem\setSection
setSection($section)
Set the section identifier.
Definition:
ElggMenuItem.php:551
ElggMenuItem\setDeps
setDeps($modules)
Set required AMD modules.
Definition:
ElggMenuItem.php:413
ElggMenuItem\getWeight
getWeight()
Get the priority of the menu item.
Definition:
ElggMenuItem.php:521
ElggMenuItem\getParentName
getParentName()
Get the parent identifier.
Definition:
ElggMenuItem.php:579
$priority
$priority
Definition:
set_priority.php:17
ElggMenuItem\__construct
__construct($name, $text, $href)
constructor
Definition:
ElggMenuItem.php:83
ElggMenuItem\getValues
getValues()
Get all the values for this menu item.
Definition:
ElggMenuItem.php:668
ElggMenuItem\getHref
getHref()
Get the URL of the menu item.
Definition:
ElggMenuItem.php:267
ElggMenuItem\$data
$data
Definition:
ElggMenuItem.php:20
ElggMenuItem\setPriority
setPriority($priority)
Set the priority of the menu item.
Definition:
ElggMenuItem.php:532
ElggMenuItem\addLinkClass
addLinkClass($class)
Add a link class.
Definition:
ElggMenuItem.php:403
Generated on Sat Dec 21 2024 00:01:04 for Elgg by
1.8.11