5use InvalidArgumentException;
36 if ( isset(
$params[
'flatlist'] ) ) {
37 $this->mClass .=
' mw-htmlform-flatlist';
42 $p = parent::validate( $value, $alldata );
48 if ( !is_string( $value ) && !is_int( $value ) ) {
49 return $this->
msg(
'htmlform-required' );
54 if ( in_array( strval( $value ), $validOptions,
true ) ) {
57 return $this->
msg(
'htmlform-select-badoption' );
71 isset( $this->mParams[
'option-descriptions'] ) ||
72 isset( $this->mParams[
'option-descriptions-messages'] ) ) {
73 throw new InvalidArgumentException(
74 "Non-Codex HTMLForms do not support the 'option-descriptions' parameter for radio buttons"
85 isset( $this->mParams[
'option-descriptions'] ) ||
86 isset( $this->mParams[
'option-descriptions-messages'] ) ) {
87 throw new InvalidArgumentException(
88 "Non-Codex HTMLForms do not support the 'option-descriptions' parameter for radio buttons"
93 foreach ( $this->
getOptions() as $label => $data ) {
94 if ( is_int( $label ) ) {
95 $label = strval( $label );
100 'label' => $this->mOptionsLabelsNotFromMessage ? new \OOUI\HtmlSnippet( $label ) : $label,
104 return new \OOUI\RadioSelectInputWidget( [
105 'name' => $this->mName,
108 'options' => $options,
109 ] + \OOUI\Element::configFromHtmlAttributes(
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 = $this->mOptionsLabelsNotFromMessage
161 ? Html::rawElement(
'label', $radioLabelAttribs, $label )
164 $radioDescription =
'';
165 if ( isset( $optionDescriptions[$radioValue] ) ) {
166 $radioDescription = Html::rawElement(
168 [
'id' => $descriptionID,
'class' =>
'cdx-label__description' ],
169 $optionDescriptions[$radioValue]
172 $radioLabelWrapper = Html::rawElement(
174 [
'class' =>
'cdx-radio__label cdx-label' ],
175 $radioLabel . $radioDescription
179 $radio = Html::rawElement(
181 [
'class' =>
'cdx-radio' ],
182 $radioInput . $radioIcon . $radioLabelWrapper
195 $attribs = $this->
getAttributes( [
'disabled',
'tabindex' ] );
196 $elementFunc = [ Html::class, $this->mOptionsLabelsNotFromMessage ?
'rawElement' :
'element' ];
198 # @todo Should this produce an unordered list perhaps?
199 foreach ( $options as $label => $info ) {
200 if ( is_array( $info ) ) {
201 $html .= Html::rawElement(
'h1', [], $label ) .
"\n";
204 $id = Sanitizer::escapeIdForAttribute( $this->mID .
"-$info" );
205 $classes = [
'mw-htmlform-flatlist-item' ];
207 $this->mName, $info, $info === $value, $attribs + [
'id' => $id ]
209 $radio .=
"\u{00A0}" . call_user_func( $elementFunc,
'label', [
'for' => $id ], $label );
211 $html .=
' ' . Html::rawElement(
213 [
'class' => $classes ],
229 if ( array_key_exists(
'option-descriptions-messages', $this->mParams ) ) {
230 $needsParse = $this->mParams[
'option-descriptions-messages-parse'] ??
false;
231 $optionDescriptions = [];
232 foreach ( $this->mParams[
'option-descriptions-messages'] as $value => $msgKey ) {
233 $msg = $this->
msg( $msgKey );
234 $optionDescriptions[$value] = $needsParse ? $msg->parse() : $msg->escaped();
236 return $optionDescriptions;
237 } elseif ( array_key_exists(
'option-descriptions', $this->mParams ) ) {
238 return $this->mParams[
'option-descriptions'];
248class_alias( HTMLRadioField::class,
'HTMLRadioField' );
array $params
The job parameters.