diff options
Diffstat (limited to 'views/default/input/radio.php')
-rw-r--r-- | views/default/input/radio.php | 49 |
1 files changed, 34 insertions, 15 deletions
diff --git a/views/default/input/radio.php b/views/default/input/radio.php index 0ad28423f..a8b278efd 100644 --- a/views/default/input/radio.php +++ b/views/default/input/radio.php @@ -10,24 +10,43 @@ * @package Elgg * @subpackage Core * - * @uses $vars['value'] The current value, if any - * @uses $vars['name'] The name of the input field - * @uses $vars['options'] An array of strings representing the options for the - * radio field as "label" => option - * @uses $vars['class'] Additional class of the list. Optional. - * @uses $vars['align'] 'horizontal' or 'vertical' Default: 'vertical' + * @uses $vars['value'] The current value, if any + * @uses $vars['name'] The name of the input field + * @uses $vars['options'] An array of strings representing the options for the + * radio field as "label" => option + * @uses $vars['class'] Additional class of the list. Optional. + * @uses $vars['align'] 'horizontal' or 'vertical' Default: 'vertical' */ -$additional_class = elgg_extract('class', $vars); -$align = elgg_extract('align', $vars, 'vertical'); -$class = "elgg-input-radio elgg-$align"; -if ($additional_class) { - $class = " $additional_class"; +$defaults = array( + 'align' => 'vertical', + 'value' => array(), + 'disabled' => false, + 'options' => array(), + 'name' => '', +); + +$vars = array_merge($defaults, $vars); + +$id = ''; +if (isset($vars['id'])) { + $id = "id=\"{$vars['id']}\""; + unset($vars['id']); + unset($vars['internalid']); +} + +$class = "elgg-input-radios elgg-{$vars['align']}"; +if (isset($vars['class'])) { + $class .= " {$vars['class']}"; unset($vars['class']); } +unset($vars['align']); +$vars['class'] = 'elgg-input-radio'; -if (isset($vars['align'])) { - unset($vars['align']); +if (is_array($vars['value'])) { + $vars['value'] = array_map('elgg_strtolower', $vars['value']); +} else { + $vars['value'] = array(elgg_strtolower($vars['value'])); } $options = $vars['options']; @@ -37,10 +56,10 @@ $value = $vars['value']; unset($vars['value']); if ($options && count($options) > 0) { - echo "<ul class=\"$class\">"; + echo "<ul class=\"$class\" $id>"; foreach ($options as $label => $option) { - $vars['checked'] = elgg_strtolower($option) == elgg_strtolower($value); + $vars['checked'] = in_array(elgg_strtolower($option), $value); $vars['value'] = $option; $attributes = elgg_format_attributes($vars); |