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(
118 foreach ( $this->
getOptions() as $label => $radioValue ) {
119 $description = $optionDescriptions[$radioValue] ??
'';
120 $descriptionID = Sanitizer::escapeIdForAttribute(
121 $this->mID .
"-$radioValue-description"
125 $radioInputClasses = [
'cdx-radio__input' ];
126 $radioInputAttribs = [
127 'id' => Sanitizer::escapeIdForAttribute( $this->mID .
"-$radioValue" ),
130 'class' => $radioInputClasses,
131 'value' => $radioValue
133 $radioInputAttribs += $this->
getAttributes( [
'disabled',
'tabindex' ] );
134 if ( $description ) {
135 $radioInputAttribs[
'aria-describedby'] = $descriptionID;
139 if ( $radioValue === $value ) {
140 $radioInputAttribs[
'checked'] =
true;
144 $radioIconClasses = [
'cdx-radio__icon' ];
145 $radioIconAttribs = [
146 'class' => $radioIconClasses,
150 $radioLabelClasses = [
'cdx-label__label' ];
151 $radioLabelAttribs = [
152 'class' => $radioLabelClasses,
153 'for' => $radioInputAttribs[
'id']
159 $radioLabel = $this->mOptionsLabelsNotFromMessage
160 ? Html::rawElement(
'label', $radioLabelAttribs, $label )
163 $radioDescription =
'';
164 if ( isset( $optionDescriptions[$radioValue] ) ) {
165 $radioDescription = Html::rawElement(
167 [
'id' => $descriptionID,
'class' =>
'cdx-label__description' ],
168 $optionDescriptions[$radioValue]
171 $radioLabelWrapper = Html::rawElement(
173 [
'class' =>
'cdx-radio__label cdx-label' ],
174 $radioLabel . $radioDescription
178 $radio = Html::rawElement(
180 [
'class' =>
'cdx-radio' ],
181 $radioInput . $radioIcon . $radioLabelWrapper
194 $attribs = $this->
getAttributes( [
'disabled',
'tabindex' ] );
195 $elementFunc = [ Html::class, $this->mOptionsLabelsNotFromMessage ?
'rawElement' :
'element' ];
197 # @todo Should this produce an unordered list perhaps?
198 foreach ( $options as $label => $info ) {
199 if ( is_array( $info ) ) {
200 $html .= Html::rawElement(
'h1', [], $label ) .
"\n";
203 $id = Sanitizer::escapeIdForAttribute( $this->mID .
"-$info" );
204 $classes = [
'mw-htmlform-flatlist-item' ];
206 $this->mName, $info, $info === $value, $attribs + [
'id' => $id ]
208 $radio .=
"\u{00A0}" . call_user_func( $elementFunc,
'label', [
'for' => $id ], $label );
210 $html .=
' ' . Html::rawElement(
212 [
'class' => $classes ],
228 if ( array_key_exists(
'option-descriptions-messages', $this->mParams ) ) {
229 $needsParse = $this->mParams[
'option-descriptions-messages-parse'] ??
false;
230 $optionDescriptions = [];
231 foreach ( $this->mParams[
'option-descriptions-messages'] as $value => $msgKey ) {
232 $msg = $this->
msg( $msgKey );
233 $optionDescriptions[$value] = $needsParse ? $msg->parse() : $msg->escaped();
235 return $optionDescriptions;
236 } elseif ( array_key_exists(
'option-descriptions', $this->mParams ) ) {
237 return $this->mParams[
'option-descriptions'];
247class_alias( HTMLRadioField::class,
'HTMLRadioField' );
array $params
The job parameters.
Module of static functions for generating XML.