Elgg  Version 6.0
button.php
Go to the documentation of this file.
1 <?php
12 $vars['class'] = elgg_extract_class($vars, 'elgg-button');
13 
14 if (!isset($vars['text']) && isset($vars['value'])) {
15  // Keeping this to ease the transition to 3.0
16  $vars['text'] = elgg_extract('value', $vars);
17 
18  elgg_deprecated_notice('Only providing a value to a button is deprecated, please also provide a text: ' . $vars['value'], '5.0');
19 }
20 
21 if (!empty($vars['confirm'])) {
22  $vars['data-confirm'] = elgg_extract('confirm', $vars);
23 
24  // if (bool) true use defaults
25  if ($vars['data-confirm'] === true) {
26  $vars['data-confirm'] = elgg_echo('question:areyousure');
27  }
28 }
29 
30 $type = elgg_extract('type', $vars, 'button', false);
31 $vars['type'] = $type;
32 
33 $text = (string) elgg_extract('text', $vars);
34 unset($vars['text']);
35 
36 if (!isset($vars['aria-label']) && !isset($vars['aria-labelledby']) && !isset($vars['title']) && empty(elgg_strip_tags($text))) {
37  elgg_log('An input/button should have a discernible text (text, title, aria-label or aria-labelledby)', 'NOTICE');
38 }
39 
40 if (!elgg_is_empty($text)) {
41  $text = elgg_format_element('span', [
42  'class' => 'elgg-button-label',
43  ], $text);
44 }
45 
46 $icon = (string) elgg_extract('icon', $vars);
47 unset($vars['icon']);
48 
49 if (!elgg_is_empty($icon) && !str_starts_with($icon, '<')) {
51  'class' => 'elgg-button-icon',
52  ]);
53 }
54 
55 $icon_alt = (string) elgg_extract('icon_alt', $vars);
56 unset($vars['icon_alt']);
57 
58 if (!elgg_is_empty($icon_alt) && !str_starts_with($icon_alt, '<')) {
60  'class' => 'elgg-button-icon-alt',
61  ]);
62 }
63 
64 switch ($type) {
65  case 'submit':
66  $vars['class'][] = 'elgg-button-submit';
67  break;
68 
69  case 'reset':
70  $vars['class'][] = 'elgg-button-cancel';
71  break;
72 }
73 
74 echo elgg_format_element('button', $vars, $icon . $text . $icon_alt);
elgg_deprecated_notice(string $msg, string $dep_version)
Log a notice about deprecated use of a function, view, etc.
Definition: elgglib.php:115
elgg_echo(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
if(!elgg_is_empty($icon)&&!str_starts_with($icon, '<')) $icon_alt
Definition: button.php:55
elgg_is_empty($value)
Check if a value isn&#39;t empty, but allow 0 and &#39;0&#39;.
Definition: input.php:176
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
if(!isset($vars['text'])&&isset($vars['value'])) if(!empty($vars['confirm'])) $type
Definition: button.php:30
elgg_log($message, $level=\Psr\Log\LogLevel::NOTICE)
Log a message.
Definition: elgglib.php:86
elgg_view_icon(string $name, array $vars=[])
View an icon glyph.
Definition: views.php:1261
if(!isset($vars['aria-label'])&&!isset($vars['aria-labelledby'])&&!isset($vars['title'])&&empty(elgg_strip_tags($text))) if(!elgg_is_empty($text)) $icon
Definition: button.php:46
$vars['class']
Renders a <button>
Definition: button.php:12
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
$text
Definition: button.php:33
elgg_strip_tags(string $string, string $allowable_tags=null)
Strip tags and offer plugins the chance.
Definition: output.php:323