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