diff --git a/src/view/form/control/select/AphrontFormSelectControl.php b/src/view/form/control/select/AphrontFormSelectControl.php index f1b84aa0a7..59f18d4ea4 100644 --- a/src/view/form/control/select/AphrontFormSelectControl.php +++ b/src/view/form/control/select/AphrontFormSelectControl.php @@ -49,16 +49,7 @@ final class AphrontFormSelectControl extends AphrontFormControl { array $options, array $attrs = array()) { - $option_tags = array(); - foreach ($options as $value => $label) { - $option_tags[] = phutil_render_tag( - 'option', - array( - 'selected' => ($value == $selected) ? 'selected' : null, - 'value' => $value, - ), - phutil_escape_html($label)); - } + $option_tags = self::renderOptions($selected, $options); return javelin_render_tag( 'select', @@ -66,4 +57,27 @@ final class AphrontFormSelectControl extends AphrontFormControl { implode("\n", $option_tags)); } + private static function renderOptions($selected, array $options) { + $tags = array(); + foreach ($options as $value => $thing) { + if (is_array($thing)) { + $tags[] = phutil_render_tag( + 'optgroup', + array( + 'label' => $value, + ), + implode("\n", self::renderOptions($selected, $thing))); + } else { + $tags[] = phutil_render_tag( + 'option', + array( + 'selected' => ($value == $selected) ? 'selected' : null, + 'value' => $value, + ), + phutil_escape_html($thing)); + } + } + return $tags; + } + }