]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Refs #2143: DRYed up input/access -- wow, that feels good
authorewinslow <ewinslow@36083f99-b078-4883-b0ff-0f9b5a30f544>
Sat, 12 Feb 2011 06:56:19 +0000 (06:56 +0000)
committerewinslow <ewinslow@36083f99-b078-4883-b0ff-0f9b5a30f544>
Sat, 12 Feb 2011 06:56:19 +0000 (06:56 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@8147 36083f99-b078-4883-b0ff-0f9b5a30f544

views/default/input/access.php

index 79807ceddd6fdae52545e2dc04ca287bab511b45..ea4654be6bfca4a517dda18191a265b5e165e8b3 100644 (file)
  *
  */
 
-$class = "elgg-input-access";
-if (isset($vars['class'])) {
-       $class = $vars['class'];
-}
+$defaults = array(
+       'class' => 'elgg-input-access',
+       'disabled' => FALSE,
+       'value' => get_default_access(),
+       'options' => get_write_access_array(),
+);
 
-$disabled = false;
-if (isset($vars['disabled'])) {
-       $disabled = $vars['disabled'];
-}
-
-if (!array_key_exists('value', $vars) || $vars['value'] == ACCESS_DEFAULT) {
-       $vars['value'] = get_default_access();
-}
-
-if ((!isset($vars['options'])) || (!is_array($vars['options']))) {
-       $vars['options'] = array();
-       $vars['options'] = get_write_access_array();
-}
+$vars = array_merge($defaults, $vars);
 
 if (is_array($vars['options']) && sizeof($vars['options']) > 0) {
-       ?>
-
-       <select <?php if (isset($vars['internalid'])) echo "id=\"{$vars['internalid']}\""; ?> name="<?php echo $vars['internalname']; ?>" <?php if (isset($vars['js'])) echo $vars['js']; ?> <?php if ($disabled) echo ' disabled="yes" '; ?> class="<?php echo $class; ?>">
-       <?php
-
-       foreach($vars['options'] as $key => $option) {
-               if ($key != $vars['value']) {
-                       echo "<option value=\"{$key}\">". htmlentities($option, ENT_QUOTES, 'UTF-8') ."</option>";
-               } else {
-                       echo "<option value=\"{$key}\" selected=\"selected\">". htmlentities($option, ENT_QUOTES, 'UTF-8') ."</option>";
-               }
-       }
-
-       ?>
-       </select>
-       <?php
+       echo elgg_view('input/dropdown', $vars);
 }
\ No newline at end of file