Merge "Improve Database related documentation a bit"
[lhc/web/wiklou.git] / includes / htmlform / HTMLMultiSelectField.php
index 09576d4..576f5cd 100644 (file)
@@ -17,7 +17,7 @@ class HTMLMultiSelectField extends HTMLFormField implements HTMLNestedFilterable
 
                # If all options are valid, array_intersect of the valid options
                # and the provided options will return the provided options.
-               $validOptions = HTMLFormField::flattenOptions( $this->mParams['options'] );
+               $validOptions = HTMLFormField::flattenOptions( $this->getOptions() );
 
                $validValues = array_intersect( $value, $validOptions );
                if ( count( $validValues ) == count( $value ) ) {
@@ -28,7 +28,8 @@ class HTMLMultiSelectField extends HTMLFormField implements HTMLNestedFilterable
        }
 
        function getInputHTML( $value ) {
-               $html = $this->formatOptions( $this->mParams['options'], $value );
+               $value = HTMLFormField::forceToStringRecursive( $value );
+               $html = $this->formatOptions( $this->getOptions(), $value );
 
                return $html;
        }
@@ -37,6 +38,7 @@ class HTMLMultiSelectField extends HTMLFormField implements HTMLNestedFilterable
                $html = '';
 
                $attribs = $this->getAttributes( array( 'disabled', 'tabindex' ) );
+               $elementFunc = array( 'Html', $this->mOptionsLabelsNotFromMessage ? 'rawElement' : 'element' );
 
                foreach ( $options as $label => $info ) {
                        if ( is_array( $info ) ) {
@@ -50,7 +52,7 @@ class HTMLMultiSelectField extends HTMLFormField implements HTMLNestedFilterable
                                        in_array( $info, $value, true ),
                                        $attribs + $thisAttribs
                                );
-                               $checkbox .= ' ' . Html::rawElement(
+                               $checkbox .= ' ' . call_user_func( $elementFunc,
                                        'label',
                                        array( 'for' => "{$this->mID}-$info" ),
                                        $label
@@ -68,9 +70,9 @@ class HTMLMultiSelectField extends HTMLFormField implements HTMLNestedFilterable
        }
 
        /**
-        * @param  $request WebRequest
+        * @param WebRequest $request
         *
-        * @return String
+        * @return string
         */
        function loadDataFromRequest( $request ) {
                if ( $this->mParent->getMethod() == 'post' ) {
@@ -102,11 +104,12 @@ class HTMLMultiSelectField extends HTMLFormField implements HTMLNestedFilterable
        }
 
        function filterDataForSubmit( $data ) {
-               $options = HTMLFormField::flattenOptions( $this->mParams['options'] );
+               $data = HTMLFormField::forceToStringRecursive( $data );
+               $options = HTMLFormField::flattenOptions( $this->getOptions() );
 
                $res = array();
                foreach ( $options as $opt ) {
-                       $res["$opt"] = in_array( $opt, $data );
+                       $res["$opt"] = in_array( $opt, $data, true );
                }
 
                return $res;