option for the each checkbox field * @uses string $vars['default'] The default value to send if nothing is checked. * Optional, defaults to 0. Set to FALSE for no default. * @uses bool $vars['disabled'] Make all input elements disabled. Optional. * @uses string $vars['value'] The current value. Single value or array. Optional. * @uses string $vars['class'] Additional class of the list. Optional. * @uses string $vars['align'] 'horizontal' or 'vertical' Default: 'vertical' * */ $defaults = array( 'align' => 'vertical', 'value' => array(), 'default' => 0, 'disabled' => false, 'options' => array(), 'name' => '', ); $vars = array_merge($defaults, $vars); if (empty($vars['options'])) { return; } $list_class = (array) elgg_extract('class', $vars, []); unset($vars['class']); $list_class[] = 'elgg-input-checkboxes'; $list_class[] = "elgg-{$vars['align']}"; $id = elgg_extract('id', $vars, ''); unset($vars['id']); if (is_array($vars['value'])) { $values = array_map('elgg_strtolower', $vars['value']); } else { $values = array(elgg_strtolower($vars['value'])); } $input_vars = $vars; $input_vars['default'] = false; if ($vars['name']) { $input_vars['name'] = "{$vars['name']}[]"; } unset($input_vars['align']); unset($input_vars['options']); // include a default value so if nothing is checked 0 will be passed. if ($vars['name'] && $vars['default'] !== false) { echo elgg_view('input/hidden', ['name' => $vars['name'], 'value' => $default]); } $checkboxes = ''; foreach ($vars['options'] as $label => $value) { // @deprecated 1.8 Remove in 1.9 if (is_integer($label)) { elgg_deprecated_notice('$vars[\'options\'] must be an associative array in input/checkboxes', 1.8); $label = $value; } $input_vars['checked'] = in_array(elgg_strtolower($value), $values); $input_vars['value'] = $value; $input_vars['label'] = $label; $input = elgg_view('input/checkbox', $input_vars); $checkboxes .= "