Elgg  Version 2.2
 All Classes Namespaces Files Functions Variables Pages
checkbox.php
Go to the documentation of this file.
1 <?php
24 $vars['class'] = (array) elgg_extract('class', $vars, []);
25 $vars['class'][] = 'elgg-input-checkbox';
26 
27 $defaults = array(
28  'default' => 0,
29  'disabled' => false,
30  'type' => 'checkbox'
31 );
32 
33 $vars = array_merge($defaults, $vars);
34 
35 $default = $vars['default'];
36 unset($vars['default']);
37 
38 if (isset($vars['name']) && $default !== false) {
39  echo elgg_view('input/hidden', ['name' => $vars['name'], 'value' => $default]);
40 }
41 
42 $label = elgg_extract('label', $vars, false);
43 $label_class = (array) elgg_extract('label_class', $vars, []);
44 $label_class[] = 'elgg-input-single-checkbox';
45 unset($vars['label']);
46 unset($vars['label_class']);
47 
49 
50 if (!empty($label)) {
51  $html_tag = elgg_extract('label_tag', $vars, 'label', false);
52  echo elgg_format_element($html_tag, ['class' => $label_class], "$input $label");
53 } else {
54  echo $input;
55 }
$label_class
Definition: checkbox.php:43
$default
Definition: checkbox.php:35
$input
Definition: checkbox.php:48
elgg_format_element($tag_name, array $attributes=array(), $text= '', array $options=array())
Format an HTML element.
Definition: output.php:218
elgg_view($view, $vars=array(), $ignore1=false, $ignore2=false, $viewtype= '')
Return a parsed view.
Definition: views.php:342
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:1310
$vars['class']
Definition: checkbox.php:24
$defaults
Definition: checkbox.php:27
if(isset($vars['name'])&&$default!==false) $label
Definition: checkbox.php:42