18 private array $options = [];
21 private string $tagName =
'select';
23 private array $attributes = [];
30 public function __construct( $name =
false, $id =
false, $default =
false ) {
39 $this->
default = $default;
46 $this->default = $default;
54 $this->tagName = $tagName;
62 $this->attributes[$name] = $value;
70 return $this->attributes[$name] ??
null;
77 public function addOption(
string $label, $value =
false ): void {
78 $value = $value !== false ? $value : $label;
79 $this->options[] = [ $label => $value ];
90 $this->options[] = $options;
102 public static function formatOptions( array $options, $default =
false ): string {
105 foreach ( $options as $label => $value ) {
106 if ( is_array( $value ) ) {
107 $contents = self::formatOptions( $value, $default );
108 $data .= Html::rawElement(
'optgroup', [
'label' => $label ], $contents ) .
"\n";
113 $selected = is_array( $default ) ? in_array( $value, $default ) : $value === $default;
114 $data .= Html::element(
116 [
'value' => $value,
'selected' => $selected ],
128 foreach ( $this->options as $options ) {
129 $contents .= self::formatOptions( $options, $this->
default );
132 return Html::rawElement( $this->tagName, $this->attributes, rtrim( $contents ) );
146 foreach ( explode(
',', $msg ) as $option ) {
147 $parts = explode(
':', $option, 2 );
149 $options[ trim( $parts[0] ) ] = trim( $parts[1] ?? $parts[0] );
155class_alias( XmlSelect::class,
'XmlSelect' );
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.