X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Fhtmlform%2Ffields%2FHTMLMultiSelectField.php;h=0d5eeba92c9e2d17ed4ed08129a48e8693b1d54d;hp=05a2ba6d5e9c08ef3a617585906b2e9f6c8e7bcd;hb=d5a7166771613dfe4ed9fb75fa5efeced6134bd1;hpb=f9e3c2d046babc7309077816b0fe9961880f4e96 diff --git a/includes/htmlform/fields/HTMLMultiSelectField.php b/includes/htmlform/fields/HTMLMultiSelectField.php index 05a2ba6d5e..0d5eeba92c 100644 --- a/includes/htmlform/fields/HTMLMultiSelectField.php +++ b/includes/htmlform/fields/HTMLMultiSelectField.php @@ -17,6 +17,11 @@ class HTMLMultiSelectField extends HTMLFormField implements HTMLNestedFilterable public function __construct( $params ) { parent::__construct( $params ); + // If the disabled-options parameter is not provided, use an empty array + if ( isset( $this->mParams['disabled-options'] ) === false ) { + $this->mParams['disabled-options'] = []; + } + // For backwards compatibility, also handle the old way with 'cssclass' => 'mw-chosen' if ( isset( $params['dropdown'] ) || strpos( $this->mClass, 'mw-chosen' ) !== false ) { $this->mClass .= ' mw-htmlform-dropdown'; @@ -75,6 +80,9 @@ class HTMLMultiSelectField extends HTMLFormField implements HTMLNestedFilterable 'id' => "{$this->mID}-$info", 'value' => $info, ]; + if ( in_array( $info, $this->mParams['disabled-options'], true ) ) { + $thisAttribs['disabled'] = 'disabled'; + } $checked = in_array( $info, $value, true ); $checkbox = $this->getOneCheckbox( $checked, $attribs + $thisAttribs, $label ); @@ -112,6 +120,18 @@ class HTMLMultiSelectField extends HTMLFormField implements HTMLNestedFilterable } } + /** + * Get options and make them into arrays suitable for OOUI. + * @return array Options for inclusion in a select or whatever. + */ + public function getOptionsOOUI() { + $options = parent::getOptionsOOUI(); + foreach ( $options as &$option ) { + $option['disabled'] = in_array( $option['data'], $this->mParams['disabled-options'], true ); + } + return $options; + } + /** * Get the OOUI version of this field. * @@ -122,7 +142,7 @@ class HTMLMultiSelectField extends HTMLFormField implements HTMLNestedFilterable public function getInputOOUI( $value ) { $this->mParent->getOutput()->addModules( 'oojs-ui-widgets' ); - $attr = $this->getTooltipAndAccessKey(); + $attr = []; $attr['id'] = $this->mID; $attr['name'] = "{$this->mName}[]"; @@ -149,7 +169,7 @@ class HTMLMultiSelectField extends HTMLFormField implements HTMLNestedFilterable /** * @param WebRequest $request * - * @return string + * @return string|array */ public function loadDataFromRequest( $request ) { if ( $this->isSubmitAttempt( $request ) ) {