Elgg  Version 2.2
 All Classes Namespaces Files Functions Variables Pages
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' => $vars['default']]);
72 }
73 
75 foreach ($vars['options'] as $label => $value) {
76  $input_vars['checked'] = in_array(elgg_strtolower($value), $values);
77  $input_vars['value'] = $value;
78  $input_vars['label'] = $label;
79 
80  $input = elgg_view('input/checkbox', $input_vars);
81 
82  $checkboxes .= "<li>$input</li>";
83 }
84 
85 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
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:218
if(empty($vars['options'])) $list_class
Definition: checkboxes.php:46
elgg_view($view, $vars=array(), $ignore1=false, $ignore2=false, $viewtype= '')
Return a parsed view.
Definition: views.php:342
$input_vars
Definition: checkboxes.php:61
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
$id
Definition: checkboxes.php:52
$label
Elgg profile plugin edit default profile action.
Definition: add.php:7
$defaults
Definition: checkboxes.php:31