From c96166173eeb385f44092ebc241e2b54bbbd1a35 Mon Sep 17 00:00:00 2001 From: Huji Lee Date: Wed, 21 Dec 2016 19:37:10 -0500 Subject: [PATCH] HTMLMultiSelect parameter to specify which options are disabled Depends on I32fa20e4adb23960d9db6bf6023f79bf128fb600 Bug: T153751 Change-Id: I3bcf6720c960e0be962e0f3f37a22ec8778db1d1 --- .../htmlform/fields/HTMLMultiSelectField.php | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/includes/htmlform/fields/HTMLMultiSelectField.php b/includes/htmlform/fields/HTMLMultiSelectField.php index 23044bd6ff..2b6e0665d5 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. * -- 2.20.1