Elgg  Version master
default.php
Go to the documentation of this file.
1 <?php
15 
17 if (!$menu instanceof PreparedMenu) {
18  return;
19 }
20 
21 // we want css classes to use dashes
22 $name = elgg_extract('name', $vars, '');
23 
24 $name_class_selector = preg_replace('/[^a-z0-9\-]/i', '-', elgg_strtolower($name));
25 
26 $show_section_headers = elgg_extract('show_section_headers', $vars, false);
27 $item_class = elgg_extract_class($vars, [], 'item_class');
28 
29 $class = elgg_extract_class($vars, ['elgg-menu', "elgg-menu-{$name_class_selector}"]);
30 
32 
33 foreach ($menu as $section) {
34  if (!$section instanceof MenuSection) {
35  continue;
36  }
37 
38  $section_class = $class;
39  $section_class_selector = preg_replace('/[^a-z0-9\-]/i', '-', elgg_strtolower($section->getID()));
40  $section_class[] = "elgg-menu-{$name_class_selector}-{$section_class_selector}";
41 
42  $menu_view .= elgg_view('navigation/menu/elements/section', [
43  'items' => $section->all(),
44  'class' => $section_class,
45  'section' => $section->getID(),
46  'name' => $name,
47  'show_section_headers' => $show_section_headers,
48  'item_class' => $item_class,
49  'id' => elgg_extract('id', $vars),
50  ]);
51 }
52 
53 if (!$menu_view) {
54  return;
55 }
56 
57 // make an ARIA label
59 if (elgg_language_key_exists("menu:{$name}:header")) {
60  $aria_label = elgg_echo("menu:{$name}:header");
61 }
62 
63 echo elgg_format_element('nav', [
64  'class' => [
65  'elgg-menu-container',
66  "elgg-menu-{$name_class_selector}-container",
67  ],
68  'data-menu-name' => $name,
69  'aria-label' => $aria_label,
70 ], $menu_view);
Menu section.
Definition: MenuSection.php:11
elgg_echo(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
$class
Definition: default.php:29
$name_class_selector
Definition: default.php:24
elgg_strtolower()
Wrapper function for mb_strtolower().
Definition: mb_wrapper.php:125
elgg_extract_class(array $array, $existing=[], $extract_key= 'class')
Extract class names from an array, optionally merging into a preexisting set.
Definition: elgglib.php:276
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
$show_section_headers
Definition: default.php:26
elgg_view(string $view, array $vars=[], string $viewtype= '')
Return a parsed view.
Definition: views.php:156
elgg_language_key_exists(string $key, string $language= 'en')
Check if a given language key exists.
Definition: languages.php:44
foreach($menu as $section) if(!$menu_view) $aria_label
Definition: default.php:58
Represents a menu that has been broken down into sections, with menu hierarchy trees setup...
if(!array_key_exists($size, $icon_sizes)) $vars['size']
Definition: default.php:25
$menu
Definition: default.php:16
elgg_format_element(string $tag_name, array $attributes=[], string $text= '', array $options=[])
Format an HTML element.
Definition: output.php:145
if(!array_key_exists($size, $icon_sizes)) $name
Definition: default.php:30
$menu_view
Definition: default.php:31
$item_class
Definition: default.php:27