public function output_html($data, $query='') {
        global $OUTPUT;

        if (!$this->load_choices() or empty($this->choices)) {
            return '';
        }

        $default = $this->get_defaultsetting();
        if (is_null($default)) {
            $default = array();
        }
        if (is_null($data)) {
            $data = array();
        }

        $context = (object) [
            'id' => $this->get_id(),
            'name' => $this->get_full_name(),
            'size' => min(10, count($this->choices))
        ];

        $defaults = [];
        $options = [];
        $template = 'core_admin/setting_configmultiselect';

        if (!empty($this->optgroups)) {
            $optgroups = [];
            foreach ($this->optgroups as $label => $choices) {
                $optgroup = array('label' => $label, 'options' => []);
                foreach ($choices as $value => $name) {
                    if (in_array($value, $default)) {
                        $defaults[] = $name;
                    }
                    $optgroup['options'][] = [
                        'value' => $value,
                        'name' => $name,
                        'selected' => in_array($value, $data)
                    ];
                    unset($this->choices[$value]);
                }
                $optgroups[] = $optgroup;
            }
            $context->optgroups = $optgroups;
            $template = 'core_admin/setting_configmultiselect_optgroup';
        }

        foreach ($this->choices as $value => $name) {
            if (in_array($value, $default)) {
                $defaults[] = $name;
            }
            $options[] = [
                'value' => $value,
                'name' => $name,
                'selected' => in_array($value, $data)
            ];
        }
        $context->options = $options;

        if (is_null($default)) {
            $defaultinfo = NULL;
        } if (!empty($defaults)) {
            $defaultinfo = implode(', ', $defaults);
        } else {
            $defaultinfo = get_string('none');
        }

        $element = $OUTPUT->render_from_template($template, $context);

        return format_admin_setting($this, $this->visiblename, $element, $this->description, true, '', $defaultinfo, $query);
    }
public function output_html($data, $query='') {
        global $OUTPUT;

        if (!$this->load_choices() or empty($this->choices)) {
            return '';
        }

        $default = $this->get_defaultsetting();
        if (is_null($default)) {
            $default = array();
        }
        if (is_null($data)) {
            $data = array();
        }

        $context = (object) [
            'id' => $this->get_id(),
            'name' => $this->get_full_name(),
            'size' => min(10, count($this->choices))
        ];

        $defaults = [];
        $options = [];
        $template = 'core_admin/setting_configmultiselect';

        if (!empty($this->optgroups)) {
            $optgroups = [];
            foreach ($this->optgroups as $label => $choices) {
                $optgroup = array('label' => $label, 'options' => []);
                foreach ($choices as $value => $name) {
                    if (in_array($value, $default)) {
                        $defaults[] = $name;
                    }
                    $optgroup['options'][] = [
                        'value' => $value,
                        'name' => $name,
                        'selected' => in_array($value, $data)
                    ];
                    unset($this->choices[$value]);
                }
                $optgroups[] = $optgroup;
            }
            $context->optgroups = $optgroups;
            $template = 'core_admin/setting_configmultiselect_optgroup';
        }

        foreach ($this->choices as $value => $name) {
            if (in_array($value, $default)) {
                $defaults[] = $name;
            }
            $options[] = [
                'value' => $value,
                'name' => $name,
                'selected' => in_array($value, $data)
            ];
        }
        $context->options = $options;

        if (is_null($default)) {
            $defaultinfo = NULL;
        } if (!empty($defaults)) {
            $defaultinfo = implode(', ', $defaults);
        } else {
            $defaultinfo = get_string('none');
        }

        $element = $OUTPUT->render_from_template($template, $context);

        return format_admin_setting($this, $this->visiblename, $element, $this->description, true, '', $defaultinfo, $query);
    }
public function output_html ( $ data , $ query = '' ) { global $ OUTPUT ; if ( ! $ this -> load_choices ( ) or empty ( $ this -> choices ) ) { return '' ; } $ default = $ this -> get_defaultsetting ( ) ; if ( is_null ( $ default ) ) { $ default = array ( ) ; } if ( is_null ( $ data ) ) { $ data = array ( ) ; } $ context = ( object ) [ 'id' => $ this -> get_id ( ) , 'name' => $ this -> get_full_name ( ) , 'size' => min ( 10 , count ( $ this -> choices ) ) ] ; $ defaults = [ ] ; $ options = [ ] ; $ template = 'core_admin/setting_configmultiselect' ; if ( ! empty ( $ this -> optgroups ) ) { $ optgroups = [ ] ; foreach ( $ this -> optgroups as $ label => $ choices ) { $ optgroup = array ( 'label' => $ label , 'options' => [ ] ) ; foreach ( $ choices as $ value => $ name ) { if ( in_array ( $ value , $ default ) ) { $ defaults [ ] = $ name ; } $ optgroup [ 'options' ] [ ] = [ 'value' => $ value , 'name' => $ name , 'selected' => in_array ( $ value , $ data ) ] ; unset ( $ this -> choices [ $ value ] ) ; } $ optgroups [ ] = $ optgroup ; } $ context -> optgroups = $ optgroups ; $ template = 'core_admin/setting_configmultiselect_optgroup' ; } foreach ( $ this -> choices as $ value => $ name ) { if ( in_array ( $ value , $ default ) ) { $ defaults [ ] = $ name ; } $ options [ ] = [ 'value' => $ value , 'name' => $ name , 'selected' => in_array ( $ value , $ data ) ] ; } $ context -> options = $ options ; if ( is_null ( $ default ) ) { $ defaultinfo = NULL ; } if ( ! empty ( $ defaults ) ) { $ defaultinfo = implode ( ', ' , $ defaults ) ; } else { $ defaultinfo = get_string ( 'none' ) ; } $ element = $ OUTPUT -> render_from_template ( $ template , $ context ) ; return format_admin_setting ( $ this , $ this -> visiblename , $ element , $ this -> description , true , '' , $ defaultinfo , $ query ) ; }
Returns XHTML multi-select field

@todo Add vartype handling to ensure $data is an array
@param array $data Array of values to select by default
@param string $query
@return string XHTML multi-select field
Returns XHTML multi - select field