35 if ( isset(
$params[
'flatlist'] ) ) {
36 $this->mClass .=
' mw-htmlform-flatlist';
41 $p = parent::validate( $value, $alldata );
47 if ( !is_string( $value ) && !is_int( $value ) ) {
48 return $this->
msg(
'htmlform-required' );
53 if ( in_array( strval( $value ), $validOptions,
true ) ) {
56 return $this->
msg(
'htmlform-select-badoption' );
70 isset( $this->mParams[
'option-descriptions'] ) ||
71 isset( $this->mParams[
'option-descriptions-messages'] ) ) {
72 throw new \InvalidArgumentException(
73 "Non-Codex HTMLForms do not support the 'option-descriptions' parameter for radio buttons"
84 isset( $this->mParams[
'option-descriptions'] ) ||
85 isset( $this->mParams[
'option-descriptions-messages'] ) ) {
86 throw new \InvalidArgumentException(
87 "Non-Codex HTMLForms do not support the 'option-descriptions' parameter for radio buttons"
92 foreach ( $this->
getOptions() as $label => $data ) {
93 if ( is_int( $label ) ) {
94 $label = strval( $label );
99 'label' => $this->mOptionsLabelsNotFromMessage ? new \OOUI\HtmlSnippet( $label ) : $label,
103 return new \OOUI\RadioSelectInputWidget( [
104 'name' => $this->mName,
107 'options' => $options,
108 ] + \OOUI\Element::configFromHtmlAttributes(
116 $elementFunc = [ Html::class, $this->mOptionsLabelsNotFromMessage ?
'rawElement' :
'element' ];
119 foreach ( $this->
getOptions() as $label => $radioValue ) {
120 $description = $optionDescriptions[$radioValue] ??
'';
121 $descriptionID = Sanitizer::escapeIdForAttribute(
122 $this->mID .
"-$radioValue-description"
126 $radioInputClasses = [
'cdx-radio__input' ];
127 $radioInputAttribs = [
128 'id' => Sanitizer::escapeIdForAttribute( $this->mID .
"-$radioValue" ),
131 'class' => $radioInputClasses,
132 'value' => $radioValue
134 $radioInputAttribs += $this->
getAttributes( [
'disabled',
'tabindex' ] );
135 if ( $description ) {
136 $radioInputAttribs[
'aria-describedby'] = $descriptionID;
140 if ( $radioValue === $value ) {
141 $radioInputAttribs[
'checked'] =
true;
145 $radioIconClasses = [
'cdx-radio__icon' ];
146 $radioIconAttribs = [
147 'class' => $radioIconClasses,
151 $radioLabelClasses = [
'cdx-label__label' ];
152 $radioLabelAttribs = [
153 'class' => $radioLabelClasses,
154 'for' => $radioInputAttribs[
'id']
160 $radioLabel = call_user_func( $elementFunc,
'label', $radioLabelAttribs, $label );
162 $radioDescription =
'';
163 if ( isset( $optionDescriptions[$radioValue] ) ) {
164 $radioDescription = Html::rawElement(
166 [
'id' => $descriptionID,
'class' =>
'cdx-label__description' ],
167 $optionDescriptions[$radioValue]
170 $radioLabelWrapper = Html::rawElement(
172 [
'class' =>
'cdx-radio__label cdx-label' ],
173 $radioLabel . $radioDescription
177 $radio = Html::rawElement(
179 [
'class' =>
'cdx-radio' ],
180 $radioInput . $radioIcon . $radioLabelWrapper
193 $attribs = $this->
getAttributes( [
'disabled',
'tabindex' ] );
194 $elementFunc = [ Html::class, $this->mOptionsLabelsNotFromMessage ?
'rawElement' :
'element' ];
196 # @todo Should this produce an unordered list perhaps?
197 foreach ( $options as $label => $info ) {
198 if ( is_array( $info ) ) {
199 $html .= Html::rawElement(
'h1', [], $label ) .
"\n";
202 $id = Sanitizer::escapeIdForAttribute( $this->mID .
"-$info" );
203 $classes = [
'mw-htmlform-flatlist-item' ];
205 $this->mName, $info, $info === $value, $attribs + [
'id' => $id ]
207 $radio .=
"\u{00A0}" . call_user_func( $elementFunc,
'label', [
'for' => $id ], $label );
209 $html .=
' ' . Html::rawElement(
211 [
'class' => $classes ],
227 if ( array_key_exists(
'option-descriptions-messages', $this->mParams ) ) {
228 $needsParse = $this->mParams[
'option-descriptions-messages-parse'] ??
false;
229 $optionDescriptions = [];
230 foreach ( $this->mParams[
'option-descriptions-messages'] as $value => $msgKey ) {
231 $msg = $this->
msg( $msgKey );
232 $optionDescriptions[$value] = $needsParse ? $msg->parse() : $msg->escaped();
234 return $optionDescriptions;
235 } elseif ( array_key_exists(
'option-descriptions', $this->mParams ) ) {
236 return $this->mParams[
'option-descriptions'];
246class_alias( HTMLRadioField::class,
'HTMLRadioField' );
array $params
The job parameters.
Module of static functions for generating XML.