Elgg  Version 5.1
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 = ['elgg-content'];
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', [
77  'class' => $class,
78  'id' => $tab_id,
79  ], $tab_content);
80 
81  // additional tab information
82  if (!isset($tab['name'])) {
83  $tab['name'] = "{$id}-tab-{$index}";
84  }
85 
86  $tab['data-target'] = "#{$tab_id}";
87  $tab['item_class'] = elgg_extract_class($tab, ['elgg-components-tab'], 'item_class');
88 
89  $tabs[$index] = $tab;
90 }
91 
92 $tabs = elgg_view('navigation/tabs', [
93  'class' => 'elgg-components-tabs',
94  'tabs' => $tabs,
95 ]);
96 
98  'class' => 'elgg-tabs-content',
99 ], $content);
100 
101 $module = (string) elgg_extract('module', $vars, 'tabs');
102 unset($vars['module']);
103 
104 echo elgg_view_module($module, (string) elgg_extract('title', $vars), $tabs . $content, $vars);
105 
106 elgg_require_js('page/components/tabs');
elgg_view_module(string $type, string $title, string $body, array $vars=[])
Wrapper function for the module display pattern.
Definition: views.php:940
$tabs
Definition: tabs.php:10
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
$module
Definition: tabs.php:101
elgg_view(string $view, array $vars=[], string $viewtype= '')
Return a parsed view.
Definition: views.php:177
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
$index
Definition: gallery.php:40
elgg_require_js(string $name)
Request that Elgg load an AMD module onto the page.