Elgg  Version 1.11
checkboxes.php
Go to the documentation of this file.
1 <?php
31 $defaults = array(
32  'align' => 'vertical',
33  'value' => array(),
34  'default' => 0,
35  'disabled' => false,
36  'options' => array(),
37  'name' => '',
38 );
39 
40 $vars = array_merge($defaults, $vars);
41 
42 if (empty($vars['options'])) {
43  return;
44 }
45 
46 $list_class = (array) elgg_extract('class', $vars, []);
47 unset($vars['class']);
48 
49 $list_class[] = 'elgg-input-checkboxes';
50 $list_class[] = "elgg-{$vars['align']}";
51 
52 $id = elgg_extract('id', $vars, '');
53 unset($vars['id']);
54 
55 if (is_array($vars['value'])) {
56  $values = array_map('elgg_strtolower', $vars['value']);
57 } else {
58  $values = array(elgg_strtolower($vars['value']));
59 }
60 
62 $input_vars['default'] = false;
63 if ($vars['name']) {
64  $input_vars['name'] = "{$vars['name']}[]";
65 }
66 unset($input_vars['align']);
67 unset($input_vars['options']);
68 
69 // include a default value so if nothing is checked 0 will be passed.
70 if ($vars['name'] && $vars['default'] !== false) {
71  echo elgg_view('input/hidden', ['name' => $vars['name'], 'value' => $default]);
72 }
73 
75 foreach ($vars['options'] as $label => $value) {
76  // @deprecated 1.8 Remove in 1.9
77  if (is_integer($label)) {
78  elgg_deprecated_notice('$vars[\'options\'] must be an associative array in input/checkboxes', 1.8);
79  $label = $value;
80  }
81 
82  $input_vars['checked'] = in_array(elgg_strtolower($value), $values);
83  $input_vars['value'] = $value;
84  $input_vars['label'] = $label;
85 
86  $input = elgg_view('input/checkbox', $input_vars);
87 
88  $checkboxes .= "<li>$input</li>";
89 }
90 
91 echo elgg_format_element('ul', ['class' => $list_class, 'id' => $id], $checkboxes);
if(!$owner||!($owner instanceof ElggUser)||!$owner->canEdit()) $input
Definition: edit.php:19
if($vars['name']&&$vars['default']!==false) $checkboxes
Definition: checkboxes.php:74
$value
Definition: longtext.php:26
$default
Definition: checkbox.php:34
elgg_extract($key, array $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:1246
elgg_strtolower()
Wrapper function for mb_strtolower().
Definition: mb_wrapper.php:174
$vars
Definition: checkboxes.php:40
elgg_format_element($tag_name, array $attributes=array(), $text= '', array $options=array())
Format an HTML element.
Definition: output.php:215
if(empty($vars['options'])) $list_class
Definition: checkboxes.php:46
elgg echo
Translates a string.
Definition: languages.js:43
elgg_deprecated_notice($msg, $dep_version, $backtrace_level=1)
Log a notice about deprecated use of a function, view, etc.
Definition: elgglib.php:1006
$input_vars
Definition: checkboxes.php:61
elgg_view($view, $vars=array(), $bypass=false, $ignored=false, $viewtype= '')
Return a parsed view.
Definition: views.php:354
$id
Definition: checkboxes.php:52
$label
Elgg profile plugin edit default profile action.
Definition: add.php:7
$defaults
Definition: checkboxes.php:31