diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2014-03-15 14:46:48 -0300 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2014-03-15 14:46:48 -0300 |
commit | 5041c6c48153453ed597206d08eeff37cf20e676 (patch) | |
tree | b25f495baf01202485f05b5245625f28558c6135 /views/default/input/radio.php | |
download | elgg-5041c6c48153453ed597206d08eeff37cf20e676.tar.gz elgg-5041c6c48153453ed597206d08eeff37cf20e676.tar.bz2 |
Squashed 'mod/cool_theme/' content from commit a26f7df
git-subtree-dir: mod/cool_theme
git-subtree-split: a26f7df43a266f7d1ff04847da330d15f6041e9b
Diffstat (limited to 'views/default/input/radio.php')
-rw-r--r-- | views/default/input/radio.php | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/views/default/input/radio.php b/views/default/input/radio.php new file mode 100644 index 000000000..ef860a773 --- /dev/null +++ b/views/default/input/radio.php @@ -0,0 +1,76 @@ +<?php +/** + * Elgg radio input + * Displays a radio input field + * + * @warning Passing integers as labels does not currently work due to a + * deprecated hack that will be removed in Elgg 1.9. To use integer labels, + * the labels must be character codes: 1 would be 1 + * + * @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' + */ + +$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']); +} + +$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 (is_array($vars['value'])) { + $vars['value'] = array_map('elgg_strtolower', $vars['value']); +} else { + $vars['value'] = array(elgg_strtolower($vars['value'])); +} + +$options = $vars['options']; +unset($vars['options']); + +$value = $vars['value']; +unset($vars['value']); + +if ($options && count($options) > 0) { + echo "<ul class=\"$class\" $id>"; + foreach ($options as $label => $option) { + + $vars['checked'] = in_array(elgg_strtolower($option), $value); + $vars['value'] = $option; + + $attributes = elgg_format_attributes($vars); + + // handle indexed array where label is not specified + // @deprecated 1.8 Remove in 1.9 + if (is_integer($label)) { + elgg_deprecated_notice('$vars[\'options\'] must be an associative array in input/radio', 1.8); + $label = $option; + } + + echo "<li><label><input type=\"radio\" $attributes />$label</label></li>"; + } + echo '</ul>'; +} |