Elgg  Version 6.1
checkbox.php
Go to the documentation of this file.
1 <?php
21 $vars['class'] = elgg_extract_class($vars, 'elgg-input-checkbox');
22 
24  'default' => 0,
25  'type' => 'checkbox',
26 ];
27 
28 $vars = array_merge($defaults, $vars);
29 
30 $default = elgg_extract('default', $vars);
31 unset($vars['default']);
32 
33 if (isset($vars['name']) && $default !== false) {
34  echo elgg_view('input/hidden', [
35  'name' => elgg_extract('name', $vars),
36  'value' => $default,
37  'disabled' => elgg_extract('disabled', $vars),
38  ]);
39 }
40 
41 $label = elgg_extract('label', $vars, false);
42 $label_class = elgg_extract_class($vars, ['elgg-input-single-checkbox'], 'label_class');
43 unset($vars['label']);
44 unset($vars['label_class']);
45 
46 $switch = elgg_extract('switch', $vars, false);
47 unset($vars['switch']);
48 
49 if ($switch) {
50  $vars['class'][] = 'hidden';
51 }
52 
54 if ($switch) {
55  $input .= elgg_format_element('span', ['class' => 'elgg-input-checkbox-switch']);
56 
57  if (empty($label)) {
58  $label = '&nbsp;';
59  }
60 }
61 
62 if (!empty($label)) {
63  $html_tag = elgg_extract('label_tag', $vars, 'label', false);
64  if ($switch && ($html_tag !== 'label')) {
65  $input = elgg_format_element('label', [], $input);
66  }
67 
68  echo elgg_format_element($html_tag, ['class' => $label_class], "$input $label");
69  return;
70 }
71 
72 echo $input;
$default
Definition: checkbox.php:30
$label_class
Definition: checkbox.php:42
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:256
$switch
Definition: checkbox.php:46
elgg_view(string $view, array $vars=[], string $viewtype= '')
Return a parsed view.
Definition: views.php:156
if(isset($vars['name'])&&$default!==false) $label
Definition: checkbox.php:41
$vars['class']
Elgg checkbox input Displays a checkbox input tag.
Definition: checkbox.php:21
elgg_format_element(string $tag_name, array $attributes=[], string $text= '', array $options=[])
Format an HTML element.
Definition: output.php:145
$defaults
Definition: checkbox.php:23
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:279
if($switch) $input
Definition: checkbox.php:53