Elgg  Version 4.x
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  'disabled' => false,
26  'type' => 'checkbox'
27 ];
28 
29 $vars = array_merge($defaults, $vars);
30 
31 $default = elgg_extract('default', $vars);
32 unset($vars['default']);
33 
34 if (isset($vars['name']) && $default !== false) {
35  echo elgg_view('input/hidden', [
36  'name' => elgg_extract('name', $vars),
37  'value' => $default,
38  'disabled' => elgg_extract('disabled', $vars),
39  ]);
40 }
41 
42 $label = elgg_extract('label', $vars, false);
43 $label_class = elgg_extract_class($vars, ['elgg-input-single-checkbox'], 'label_class');
44 unset($vars['label']);
45 unset($vars['label_class']);
46 
47 $switch = elgg_extract('switch', $vars, false);
48 unset($vars['switch']);
49 
50 if ($switch) {
51  $vars['class'][] = 'hidden';
52 }
53 
55 if ($switch) {
56  $input .= elgg_format_element('span', ['class' => 'elgg-input-checkbox-switch']);
57 
58  if (empty($label)) {
59  $label = '&nbsp;';
60  }
61 }
62 
63 if (!empty($label)) {
64  $html_tag = elgg_extract('label_tag', $vars, 'label', false);
65  if ($switch && ($html_tag !== 'label')) {
66  $input = elgg_format_element('label', [], $input);
67  }
68  echo elgg_format_element($html_tag, ['class' => $label_class], "$input $label");
69 } else {
70  echo $input;
71 }
$default
Definition: checkbox.php:31
$label_class
Definition: checkbox.php:43
elgg_extract_class(array $array, $existing=[], $extract_key= 'class')
Extract class names from an array, optionally merging into a preexisting set.
Definition: elgglib.php:708
$switch
Definition: checkbox.php:47
if(isset($vars['name'])&&$default!==false) $label
Definition: checkbox.php:42
elgg_format_element($tag_name, array $attributes=[], $text= '', array $options=[])
Format an HTML element.
Definition: output.php:134
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:686
$vars['class']
Elgg checkbox input Displays a checkbox input tag.
Definition: checkbox.php:21
elgg echo
Translates a string.
Definition: deprecated.js:530
$defaults
Definition: checkbox.php:23
elgg_view($view, $vars=[], $viewtype= '')
Return a parsed view.
Definition: views.php:205
if($switch) $input
Definition: checkbox.php:54