[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class AphrontFormSelectControl extends AphrontFormControl { 4 5 protected function getCustomControlClass() { 6 return 'aphront-form-control-select'; 7 } 8 9 private $options; 10 private $disabledOptions = array(); 11 12 public function setOptions(array $options) { 13 $this->options = $options; 14 return $this; 15 } 16 17 public function getOptions() { 18 return $this->options; 19 } 20 21 public function setDisabledOptions(array $disabled) { 22 $this->disabledOptions = $disabled; 23 return $this; 24 } 25 26 protected function renderInput() { 27 return self::renderSelectTag( 28 $this->getValue(), 29 $this->getOptions(), 30 array( 31 'name' => $this->getName(), 32 'disabled' => $this->getDisabled() ? 'disabled' : null, 33 'id' => $this->getID(), 34 ), 35 $this->disabledOptions); 36 } 37 38 public static function renderSelectTag( 39 $selected, 40 array $options, 41 array $attrs = array(), 42 array $disabled = array()) { 43 44 $option_tags = self::renderOptions($selected, $options, $disabled); 45 46 return javelin_tag( 47 'select', 48 $attrs, 49 $option_tags); 50 } 51 52 private static function renderOptions( 53 $selected, 54 array $options, 55 array $disabled = array()) { 56 $disabled = array_fuse($disabled); 57 58 $tags = array(); 59 foreach ($options as $value => $thing) { 60 if (is_array($thing)) { 61 $tags[] = phutil_tag( 62 'optgroup', 63 array( 64 'label' => $value, 65 ), 66 self::renderOptions($selected, $thing)); 67 } else { 68 $tags[] = phutil_tag( 69 'option', 70 array( 71 'selected' => ($value == $selected) ? 'selected' : null, 72 'value' => $value, 73 'disabled' => isset($disabled[$value]) ? 'disabled' : null, 74 ), 75 $thing); 76 } 77 } 78 return $tags; 79 } 80 81 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |