Elgg  Version 6.3
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 
50 if ($switch) {
51  $input = elgg_format_element('span', ['class' => 'elgg-input-checkbox-switch'], $input . elgg_format_element('span'));
52 
53  if (empty($label)) {
54  $label = '&nbsp;';
55  }
56 }
57 
58 if (!empty($label)) {
59  $html_tag = elgg_extract('label_tag', $vars, 'label', false);
60  if ($switch && ($html_tag !== 'label')) {
61  $input = elgg_format_element('label', [], $input);
62  }
63 
64  echo elgg_format_element($html_tag, ['class' => $label_class], "$input $label");
65  return;
66 }
67 
68 echo $input;
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:263
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:240
$label_class
Definition: checkbox.php:42
if(isset($vars['name']) && $default !==false) $label
Definition: checkbox.php:41
$defaults
Definition: checkbox.php:23
$input
Definition: checkbox.php:49
$vars['class']
Elgg checkbox input Displays a checkbox input tag.
Definition: checkbox.php:21
$default
Definition: checkbox.php:30
$switch
Definition: checkbox.php:46
elgg_view(string $view, array $vars=[], string $viewtype='')
Return a parsed view.
Definition: views.php:156
elgg_format_element(string $tag_name, array $attributes=[], string $text='', array $options=[])
Format an HTML element.
Definition: output.php:145