Elgg  Version 4.3
button.php
Go to the documentation of this file.
1 <?php
2 
13 $vars['class'] = elgg_extract_class($vars, 'elgg-button');
14 
15 if (!isset($vars['text']) && isset($vars['value'])) {
16  // Keeping this to ease the transition to 3.0
17  $vars['text'] = elgg_extract('value', $vars);
18 }
19 
20 if (!empty($vars['confirm'])) {
21  $vars['data-confirm'] = elgg_extract('confirm', $vars);
22 
23  // if (bool) true use defaults
24  if ($vars['data-confirm'] === true) {
25  $vars['data-confirm'] = elgg_echo('question:areyousure');
26  }
27 }
28 
29 $type = elgg_extract('type', $vars, 'button', false);
30 $vars['type'] = $type;
31 
33 unset($vars['text']);
34 
35 $text = elgg_format_element('span', [
36  'class' => 'elgg-button-label',
37 ], $text);
38 
39 $icon = elgg_extract('icon', $vars, '');
40 unset($vars['icon']);
41 
42 if ($icon && !preg_match('/^</', $icon)) {
44  'class' => 'elgg-button-icon',
45  ]);
46 }
47 
48 $icon_alt = elgg_extract('icon_alt', $vars, '');
49 unset($vars['icon_alt']);
50 
51 if ($icon_alt && !preg_match('/^</', $icon_alt)) {
53  'class' => 'elgg-button-icon-alt',
54  ]);
55 }
56 
57 switch ($type) {
58  case 'submit':
59  $vars['class'][] = 'elgg-button-submit';
60  break;
61 
62  case 'reset':
63  $vars['class'][] = 'elgg-button-cancel';
64  break;
65 }
66 
elgg_echo($message_key, array $args=[], $language="")
Elgg language module Functions to manage language and translations.
Definition: languages.php:18
elgg_extract_class(array $array, $existing=[], $extract_key= 'class')
Extract class names from an array, optionally merging into a preexisting set.
Definition: elgglib.php:569
if($icon &&!preg_match('/^</', $icon) $icon_alt)
Definition: button.php:48
if(!isset($vars['text'])&&isset($vars['value'])) if(!empty($vars['confirm'])) $type
Definition: button.php:29
elgg_format_element($tag_name, array $attributes=[], $text= '', array $options=[])
Format an HTML element.
Definition: output.php:135
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:547
$icon
Definition: button.php:39
elgg_view_icon($name, $vars=[])
View an icon glyph.
Definition: views.php:1297
$vars['class']
Renders a <button>
Definition: button.php:13
elgg echo
Translates a string.
Definition: deprecated.js:530
$text
Definition: button.php:32