Elgg  Version 2.3
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"
51  requires either a "href" or "content" parameter', 'ERROR');
52  continue;
53  }
54 
55  $selected = elgg_extract('selected', $tab);
56 
57  if (isset($tab['content'])) {
58  $class = ['elgg-content'];
59  $class[] = $selected ? 'elgg-state-active' : 'hidden';
60 
61  $content .= elgg_format_element('div', [
62  'class' => $class,
63  'id' => "{$id}-{$index}",
64  ], $tab['content']);
65  unset($tab['content']);
66 
67  $tab['href'] = "#{$id}-{$index}";
68  } else {
69  if (!isset($tab['data-ajax-reload'])) {
70  $tab['data-ajax-reload'] = true;
71  }
72  }
73 
74  $tabs[$index] = $tab;
75 }
76 
77 $tabs = elgg_view('navigation/tabs', [
78  'tabs' => $tabs,
79 ]);
80 
82  'class' => 'elgg-tabs-content',
83 ], $content);
84 
85 $module = elgg_extract('module', $vars, 'tabs');
86 unset($vars['module']);
88 
89 ?>
90 <script>
91  require(['page/components/tabs']);
92 </script>
93 
$tabs
Definition: tabs.php:41
$class
Definition: field.php:20
elgg_extract_class(array $array, $existing=[])
Extract class names from an array with key "class", optionally merging into a preexisting set...
Definition: elgglib.php:1396
elgg_format_element($tag_name, array $attributes=array(), $text= '', array $options=array())
Format an HTML element.
Definition: output.php:208
$module
Definition: tabs.php:85
elgg echo
Translates a string.
Definition: languages.js:48
$id
Tabbed module component Provides support for inline and ajax tabbing.
Definition: tabs.php:33
if(empty($tabs)) $content
Definition: tabs.php:47
elgg require
Throw an error if the required package isn&#39;t present.
Definition: elgglib.js:164
elgg_view($view, $vars=array(), $ignore1=false, $ignore2=false, $viewtype= '')
Return a parsed view.
Definition: views.php:336
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:1375
elgg_view_module($type, $title, $body, array $vars=array())
Wrapper function for the module display pattern.
Definition: views.php:1250
elgg_log($message, $level= 'NOTICE')
Display or log a message.
Definition: elgglib.php:1028
$index
Definition: gallery.php:49
if(!isset($vars['id'])) $vars['id']
Definition: tabs.php:37