]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Fixes #2143: DRYed up input/radio -- other views still should be addressed, but not...
authorewinslow <ewinslow@36083f99-b078-4883-b0ff-0f9b5a30f544>
Sat, 12 Feb 2011 07:16:02 +0000 (07:16 +0000)
committerewinslow <ewinslow@36083f99-b078-4883-b0ff-0f9b5a30f544>
Sat, 12 Feb 2011 07:16:02 +0000 (07:16 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@8149 36083f99-b078-4883-b0ff-0f9b5a30f544

views/default/input/radio.php

index 9f4c71d32bfbf70e7b80e6e30d0aa937beb92569..c897b48f18ebb3d9b460293d510545e095696242 100644 (file)
  *
  */
 
-$class = $vars['class'];
-if (!$class) {
-       $class = "elgg-input-radio";
-}
+$defaults = array(
+       'class' => 'elgg-input-radio',
+);
 
-foreach ($vars['options'] as $label => $option) {
-       if (strtolower($option) != strtolower($vars['value'])) {
-               $selected = "";
-       } else {
-               $selected = "checked = \"checked\"";
-       }
+$vars = array_merge($defaults, $vars);
+
+$options = $vars['options'];
+unset($vars['options']);
 
+$value = $vars['value'];
+unset($vars['value']);
+
+foreach ($options as $label => $option) {
+       
+       $vars['checked'] = strtolower($option) != strtolower($vars['value']);
+       $vars['value'] = $option;
+       
+       $attributes = elgg_format_attributes($vars);
+       
        // handle indexed array where label is not specified
        // @todo deprecate in Elgg 1.8
        if (is_integer($label)) {
                $label = $option;
        }
        
-       if (isset($vars['internalid'])) {
-               $id = "id=\"{$vars['internalid']}\"";
-       }
-       if ($vars['disabled']) {
-               $disabled = ' disabled="yes" ';
-       }
-       echo "<label><input type=\"radio\" $disabled {$vars['js']} name=\"{$vars['internalname']}\" $id value=\"".htmlentities($option, ENT_QUOTES, 'UTF-8')."\" {$selected} class=\"$class\" />{$label}</label><br />";
+       echo "<label><input type=\"radio\" $attributes />$label</label><br />";
 }
\ No newline at end of file