SessionManager: Ignore Session object destruction during global shutdown
[mediawiki.git] / includes / htmlform / HTMLSelectField.php
blobb6ad46c5ae483e176a5f8f751474c2f9a272dee7
1 <?php
3 /**
4 * A select dropdown field. Basically a wrapper for Xmlselect class
5 */
6 class HTMLSelectField extends HTMLFormField {
7 function validate( $value, $alldata ) {
8 $p = parent::validate( $value, $alldata );
10 if ( $p !== true ) {
11 return $p;
14 $validOptions = HTMLFormField::flattenOptions( $this->getOptions() );
16 if ( in_array( strval( $value ), $validOptions, true ) ) {
17 return true;
18 } else {
19 return $this->msg( 'htmlform-select-badoption' )->parse();
23 function getInputHTML( $value ) {
24 $select = new XmlSelect( $this->mName, $this->mID, strval( $value ) );
26 if ( !empty( $this->mParams['disabled'] ) ) {
27 $select->setAttribute( 'disabled', 'disabled' );
30 $allowedParams = [ 'tabindex', 'size' ];
31 $customParams = $this->getAttributes( $allowedParams );
32 foreach ( $customParams as $name => $value ) {
33 $select->setAttribute( $name, $value );
36 if ( $this->mClass !== '' ) {
37 $select->setAttribute( 'class', $this->mClass );
40 $select->addOptions( $this->getOptions() );
42 return $select->getHTML();
45 function getInputOOUI( $value ) {
46 $disabled = false;
47 $allowedParams = [ 'tabindex' ];
48 $attribs = OOUI\Element::configFromHtmlAttributes(
49 $this->getAttributes( $allowedParams )
52 if ( $this->mClass !== '' ) {
53 $attribs['classes'] = [ $this->mClass ];
56 if ( !empty( $this->mParams['disabled'] ) ) {
57 $disabled = true;
60 return new OOUI\DropdownInputWidget( [
61 'name' => $this->mName,
62 'id' => $this->mID,
63 'options' => $this->getOptionsOOUI(),
64 'value' => strval( $value ),
65 'disabled' => $disabled,
66 ] + $attribs );