Elgg  Version 6.0
tabs.php
Go to the documentation of this file.
1 <?php
34 if (!isset($id)) {
35  $id = 'elgg-tabs-' . base_convert(mt_rand(), 10, 36);
36 }
37 
38 $vars['id'] = $id;
39 
40 $vars['class'] = elgg_extract_class($vars, 'elgg-tabs-component');
41 
42 $tabs = (array) elgg_extract('tabs', $vars, []);
43 unset($vars['tabs']);
44 if (empty($tabs)) {
45  return;
46 }
47 
48 $content = '';
49 foreach ($tabs as $index => $tab) {
50  if (!isset($tab['href']) && !isset($tab['content'])) {
51  elgg_log('Tab configuration in "page/components/tabs" requires either a "href" or "content" parameter', 'NOTICE');
52  continue;
53  }
54 
55  $selected = (bool) elgg_extract('selected', $tab, false);
56 
57  $class = [];
58  $tab_content = '';
59  $tab_id = "{$id}-{$index}";
60  if (isset($tab['content'])) {
61  $class[] = $selected ? 'elgg-state-active' : 'hidden';
62 
63  $tab_content = (string) elgg_extract('content', $tab);
64  unset($tab['content']);
65 
66  $tab['href'] = "#{$tab_id}";
67  } else {
68  if (!isset($tab['data-ajax-reload'])) {
69  $tab['data-ajax-reload'] = true;
70  }
71 
72  $class[] = 'hidden';
73  }
74 
75  // place for content
76  $content .= elgg_format_element('div', ['class' => $class, 'id' => $tab_id], $tab_content);
77 
78  // additional tab information
79  if (!isset($tab['name'])) {
80  $tab['name'] = "{$id}-tab-{$index}";
81  }
82 
83  $tab['data-target'] = "#{$tab_id}";
84  $tab['item_class'] = elgg_extract_class($tab, 'elgg-components-tab', 'item_class');
85 
86  $tabs[$index] = $tab;
87 }
88 
89 $tabs = elgg_view('navigation/tabs', [
90  'class' => 'elgg-components-tabs',
91  'tabs' => $tabs,
92 ]);
93 
94 $content = elgg_format_element('div', ['class' => 'elgg-tabs-content'], $content);
95 
96 $module = (string) elgg_extract('module', $vars, 'tabs');
97 unset($vars['module']);
98 
99 echo elgg_view_module($module, (string) elgg_extract('title', $vars), $tabs . $content, $vars);
100 
101 elgg_import_esm('page/components/tabs');
elgg_view_module(string $type, string $title, string $body, array $vars=[])
Wrapper function for the module display pattern.
Definition: views.php:919
$tabs
Definition: tabs.php:10
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
$module
Definition: tabs.php:96
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.
elgg_log($message, $level=\Psr\Log\LogLevel::NOTICE)
Log a message.
Definition: elgglib.php:86
if(!isset($id)) $vars['id']
Definition: tabs.php:38
$id
Tabbed module component Provides support for inline and ajax tabbing.
Definition: tabs.php:33
if(empty($tabs)) $content
Definition: tabs.php:48
$selected
Admin helper view for tabs on the different security pages.
Definition: tabs.php:8
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
$index
Definition: gallery.php:40