aboutsummaryrefslogtreecommitdiff
path: root/views/default/input/checkboxes.php
diff options
context:
space:
mode:
authorCash Costello <cash.costello@gmail.com>2011-07-02 09:21:30 -0400
committerCash Costello <cash.costello@gmail.com>2011-07-02 09:21:30 -0400
commitf5f3f205e97c2a3219897dd14de7d57659ce1181 (patch)
treee89da8c8aa003826b1815cabaf01d1fbcfbb351f /views/default/input/checkboxes.php
parent9e9b28479b6ecfd8685b2bba7f9ae5856ece9b2e (diff)
downloadelgg-f5f3f205e97c2a3219897dd14de7d57659ce1181.tar.gz
elgg-f5f3f205e97c2a3219897dd14de7d57659ce1181.tar.bz2
Fixes #3624 input views use class extending rather than overriding
Diffstat (limited to 'views/default/input/checkboxes.php')
-rw-r--r--views/default/input/checkboxes.php99
1 files changed, 54 insertions, 45 deletions
diff --git a/views/default/input/checkboxes.php b/views/default/input/checkboxes.php
index c78fe4db0..985858b85 100644
--- a/views/default/input/checkboxes.php
+++ b/views/default/input/checkboxes.php
@@ -15,68 +15,77 @@
* @package Elgg
* @subpackage Core
*
- * @uses string $vars['name'] The name of the input fields
- * (Forced to an array by appending [])
- * @uses array $vars['options'] An array of strings representing the
- * label => option for the each checkbox field
- * @uses string $vars['id'] The id for each input field. Optional.
- * (Only use this with a single value.)
- * @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. Optional.
- * @uses string $vars['class'] Additional class of the list. Optional.
- * @uses string $vars['align'] 'horizontal' or 'vertical' Default: 'vertical'
+ * @uses string $vars['name'] The name of the input fields
+ * (Forced to an array by appending [])
+ * @uses array $vars['options'] An array of strings representing the
+ * label => 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'
*
*/
-$additional_class = elgg_extract('class', $vars);
-$align = elgg_extract('align', $vars, 'vertical');
-$value = (isset($vars['value'])) ? $vars['value'] : NULL;
-$value_array = (is_array($value)) ? array_map('elgg_strtolower', $value) : array(elgg_strtolower($value));
-$name = (isset($vars['name'])) ? $vars['name'] : '';
-$options = (isset($vars['options']) && is_array($vars['options'])) ? $vars['options'] : array();
-$default = (isset($vars['default'])) ? $vars['default'] : 0;
+$defaults = array(
+ 'align' => 'vertical',
+ 'value' => array(),
+ 'default' => 0,
+ 'disabled' => false,
+ 'options' => array(),
+ 'name' => '',
+);
-$id = (isset($vars['id'])) ? $vars['id'] : '';
-$disabled = (isset($vars['disabled'])) ? $vars['disabled'] : FALSE;
-$js = (isset($vars['js'])) ? $vars['js'] : '';
+$vars = array_merge($defaults, $vars);
-$class = "elgg-input-checkboxes elgg-$align";
-if ($additional_class) {
- $class = " $additional_class";
+$class = "elgg-input-checkboxes elgg-{$vars['align']}";
+if (isset($vars['class'])) {
+ $class .= " {$vars['class']}";
+ unset($vars['class']);
}
-if ($options && count($options) > 0) {
+$id = '';
+if (isset($vars['id'])) {
+ $id = "id=\"{$vars['id']}\"";
+ unset($vars['id']);
+ unset($vars['internalid']);
+}
+
+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']);
+
+if (count($vars['options']) > 0) {
// include a default value so if nothing is checked 0 will be passed.
- if ($name && $default !== FALSE) {
- echo "<input type=\"hidden\" name=\"$name\" value=\"$default\" />";
+ if ($vars['name'] && $vars['default'] !== false) {
+ echo "<input type=\"hidden\" name=\"{$vars['name']}\" value=\"{$vars['default']}\" />";
}
- echo "<ul class=\"$class\">";
- foreach ($options as $label => $option) {
+ echo "<ul class=\"$class\" $id>";
+ 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 = $option;
+ $label = $value;
}
- $input_vars = array(
- 'checked' => in_array(elgg_strtolower($option), $value_array),
- 'value' => $option,
- 'disabled' => $disabled,
- 'id' => $id,
- 'js' => $js,
- 'default' => false,
- );
-
- if ($name) {
- $input_vars['name'] = "{$name}[]";
- }
+ $input_vars['checked'] = in_array(elgg_strtolower($value), $values);
+ $input_vars['value'] = $value;
$input = elgg_view('input/checkbox', $input_vars);
- echo "<li><label>{$input}{$label}</label></li>";
+ echo "<li><label>$input$label</label></li>";
}
echo '</ul>';
-} \ No newline at end of file
+}