Changeset View
Changeset View
Standalone View
Standalone View
src/view/form/control/AphrontFormSelectControl.php
| Show First 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | final class AphrontFormSelectControl extends AphrontFormControl { | ||||
| private static function renderOptions( | private static function renderOptions( | ||||
| $selected, | $selected, | ||||
| array $options, | array $options, | ||||
| array $disabled = array()) { | array $disabled = array()) { | ||||
| $disabled = array_fuse($disabled); | $disabled = array_fuse($disabled); | ||||
| $tags = array(); | $tags = array(); | ||||
| $already_selected = false; | |||||
| foreach ($options as $value => $thing) { | foreach ($options as $value => $thing) { | ||||
| if (is_array($thing)) { | if (is_array($thing)) { | ||||
| $tags[] = phutil_tag( | $tags[] = phutil_tag( | ||||
| 'optgroup', | 'optgroup', | ||||
| array( | array( | ||||
| 'label' => $value, | 'label' => $value, | ||||
| ), | ), | ||||
| self::renderOptions($selected, $thing)); | self::renderOptions($selected, $thing)); | ||||
| } else { | } else { | ||||
| // When there are a list of options including similar values like | |||||
| // "0" and "" (the empty string), only select the first matching | |||||
| // value. Ideally this should be more precise about matching, but we | |||||
| // have 2,000 of these controls at this point so hold that for a | |||||
| // broader rewrite. | |||||
| if (!$already_selected && ($value == $selected)) { | |||||
| $is_selected = 'selected'; | |||||
| $already_selected = true; | |||||
| } else { | |||||
| $is_selected = null; | |||||
| } | |||||
| $tags[] = phutil_tag( | $tags[] = phutil_tag( | ||||
| 'option', | 'option', | ||||
| array( | array( | ||||
| 'selected' => ($value == $selected) ? 'selected' : null, | 'selected' => $is_selected, | ||||
| 'value' => $value, | 'value' => $value, | ||||
| 'disabled' => isset($disabled[$value]) ? 'disabled' : null, | 'disabled' => isset($disabled[$value]) ? 'disabled' : null, | ||||
| ), | ), | ||||
| $thing); | $thing); | ||||
| } | } | ||||
| } | } | ||||
| return $tags; | return $tags; | ||||
| } | } | ||||
| } | } | ||||