Elgg  Version master
item.php
Go to the documentation of this file.
1 <?php
9 $item = elgg_extract('item', $vars);
10 if (!$item instanceof ElggMenuItem) {
11  return;
12 }
13 
16 
17 $children = $item->getChildren();
18 if (!empty($children)) {
19  $link_class = 'elgg-menu-closed';
20  if ($item->getSelected()) {
21  $link_class = 'elgg-menu-opened';
22  }
23 
24  $item->addLinkClass($link_class);
25 
26  $item->addLinkClass('elgg-menu-parent');
27 
28  $child_menu_vars = $item->getChildMenuOptions();
29  $child_menu_vars['items'] = $children;
30  $child_menu_vars['class'] = elgg_extract_class($child_menu_vars, ['elgg-menu', 'elgg-child-menu']);
31 
32  $display = elgg_extract('display', $child_menu_vars, 'default');
33  unset($child_menu_vars['display']);
34 
35  switch ($display) {
36  case 'dropdown':
37  $item->addDeps(['elgg/menus/dropdown']);
38  $item->addItemClass('elgg-menu-item-has-dropdown');
39  break;
40 
41  case 'toggle':
42  $item->addDeps(['elgg/menus/toggle']);
43  $item->addItemClass('elgg-menu-item-has-toggle');
44  break;
45  }
46 
47  $child_menu_view = elgg_view('navigation/menu/elements/section', $child_menu_vars);
48 } elseif ($item->getData('show_with_empty_children') === false) {
49  return;
50 }
51 
52 $deps = $item->getDeps();
53 if (elgg_extract('data-toggle', $item->getValues())) {
54  $deps[] = 'navigation/menu/elements/item_toggle';
55 }
56 
57 foreach ($deps as $module) {
58  elgg_import_esm($module);
59 }
60 
61 $item_vars['data-menu-item'] = $item->getName();
62 
63 $item_vars['class'] = elgg_extract_class($vars, $item->getItemClass(), 'item_class');
64 if ($item->getSelected()) {
65  $item_vars['class'][] = 'elgg-state-selected';
66 }
67 
68 $item_view = elgg_view($item->getItemContentsView() ?: 'navigation/menu/elements/item/url', [
69  'item' => $item,
70 ]);
71 
73 
if(!$item instanceof ElggMenuItem) $item_vars
Definition: item.php:14
$module
Elgg login box.
Definition: login_box.php:8
if(!empty($children)) elseif($item->getData('show_with_empty_children')===false) $deps
Definition: item.php:52
$children
Definition: item.php:17
if($item instanceof\ElggEntity) elseif($item instanceof\ElggRiverItem) elseif($item instanceof\ElggRelationship) elseif(is_callable([$item, 'getType']))
Definition: item.php:48
Elgg Menu Item.
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:254
elgg_view(string $view, array $vars=[], string $viewtype= '')
Return a parsed view.
Definition: views.php:156
elgg_import_esm(string $name)
Helper functions for external files like css/js.
$item
A single element of a menu.
Definition: item.php:9
$vars
Definition: theme.php:5
$child_menu_view
Definition: item.php:15
elgg_format_element(string $tag_name, array $attributes=[], string $text= '', array $options=[])
Format an HTML element.
Definition: output.php:145
elgg_extract_class(array $array, array|string $existing=[], string $extract_key= 'class')
Extract class names from an array, optionally merging into a preexisting set.
Definition: elgglib.php:277
if($item->getSelected()) $item_view
Definition: item.php:68