Elgg  Version 3.0
tabs.php
Go to the documentation of this file.
1 <?php
34 if (!isset($vars['id'])) {
35  $id = "elgg-tabs-" . base_convert(mt_rand(), 10, 36);
36 }
37 $vars['id'] = $id;
38 
39 $vars['class'] = elgg_extract_class($vars, 'elgg-tabs-component');
40 
41 $tabs = (array) elgg_extract('tabs', $vars, []);
42 unset($vars['tabs']);
43 if (empty($tabs)) {
44  return;
45 }
46 
47 $content = '';
48 foreach ($tabs as $index => $tab) {
49  if (!isset($tab['href']) && !isset($tab['content'])) {
50  elgg_log('Tab configuration in "page/components/tabs" requires either a "href" or "content" parameter', 'NOTICE');
51  continue;
52  }
53 
54  $selected = elgg_extract('selected', $tab);
55 
56  $class = ['elgg-content'];
57  $tab_content = '';
58  $tab_id = "{$id}-{$index}";
59  if (isset($tab['content'])) {
60  $class[] = $selected ? 'elgg-state-active' : 'hidden';
61 
62  $tab_content = elgg_extract('content', $tab);
63  unset($tab['content']);
64 
65  $tab['href'] = "#{$tab_id}";
66  } else {
67  if (!isset($tab['data-ajax-reload'])) {
68  $tab['data-ajax-reload'] = true;
69  }
70 
71  $class[] = 'hidden';
72  }
73 
74  // place for content
75  $content .= elgg_format_element('div', [
76  'class' => $class,
77  'id' => $tab_id,
78  ], $tab_content);
79 
80  // additional tab information
81  if (!isset($tab['name'])) {
82  $tab['name'] = "{$id}-tab-{$index}";
83  }
84 
85  $tab['data-target'] = "#{$tab_id}";
86  $tab['item_class'] = elgg_extract_class($tab, ['elgg-components-tab'], 'item_class');
87 
88  $tabs[$index] = $tab;
89 }
90 
91 $tabs = elgg_view('navigation/tabs', [
92  'class' => 'elgg-components-tabs',
93  'tabs' => $tabs,
94 ]);
95 
97  'class' => 'elgg-tabs-content',
98 ], $content);
99 
100 $module = elgg_extract('module', $vars, 'tabs');
101 unset($vars['module']);
102 
104 
105 elgg_require_js('page/components/tabs');
elgg_extract_class(array $array, $existing=[], $extract_key= 'class')
Extract class names from an array, optionally merging into a preexisting set.
Definition: elgglib.php:1153
$module
Definition: tabs.php:100
elgg_require_js($name)
Request that Elgg load an AMD module onto the page.
Definition: elgglib.php:168
elgg_format_element($tag_name, array $attributes=[], $text= '', array $options=[])
Format an HTML element.
Definition: output.php:168
elgg_log($message, $level=\Psr\Log\LogLevel::NOTICE)
Log a message.
Definition: elgglib.php:786
elgg_view_module($type, $title, $body, array $vars=[])
Wrapper function for the module display pattern.
Definition: views.php:1198
elgg echo
Translates a string.
Definition: languages.js:43
$id
Tabbed module component Provides support for inline and ajax tabbing.
Definition: tabs.php:33
if(empty($tabs)) $content
Definition: tabs.php:47
elgg_extract($key, $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:1131
$index
Definition: gallery.php:47
elgg_view($view, $vars=[], $viewtype= '')
Return a parsed view.
Definition: views.php:246
if(!isset($vars['id'])) $vars['id']
Definition: tabs.php:37