3 final class AphrontFormSelectControl
extends AphrontFormControl
{
5 protected function getCustomControlClass() {
6 return 'aphront-form-control-select';
10 private $disabledOptions = array();
12 public function setOptions(array $options) {
13 $this->options
= $options;
17 public function getOptions() {
18 return $this->options
;
21 public function setDisabledOptions(array $disabled) {
22 $this->disabledOptions
= $disabled;
26 protected function renderInput() {
27 return self
::renderSelectTag(
31 'name' => $this->getName(),
32 'disabled' => $this->getDisabled() ?
'disabled' : null,
33 'id' => $this->getID(),
35 $this->disabledOptions
);
38 public static function renderSelectTag(
41 array $attrs = array(),
42 array $disabled = array()) {
44 $option_tags = self
::renderOptions($selected, $options, $disabled);
52 private static function renderOptions(
55 array $disabled = array()) {
56 $disabled = array_fuse($disabled);
59 $already_selected = false;
60 foreach ($options as $value => $thing) {
61 if (is_array($thing)) {
67 self
::renderOptions($selected, $thing));
69 // When there are a list of options including similar values like
70 // "0" and "" (the empty string), only select the first matching
71 // value. Ideally this should be more precise about matching, but we
72 // have 2,000 of these controls at this point so hold that for a
74 if (!$already_selected && ($value == $selected)) {
75 $is_selected = 'selected';
76 $already_selected = true;
84 'selected' => $is_selected,
86 'disabled' => isset($disabled[$value]) ?
'disabled' : null,