Contao\CheckBoxWizard::generate PHP Method

generate() public method

Generate the widget and return it as string
public generate ( ) : string
return string
    public function generate()
    {
        if (!is_array($this->varValue)) {
            $this->varValue = array($this->varValue);
        }
        // Sort options
        if ($this->varValue) {
            $arrOptions = array();
            $arrTemp = $this->arrOptions;
            // Move selected and sorted options to the top
            foreach ($this->arrOptions as $i => $arrOption) {
                if (($intPos = array_search($arrOption['value'], $this->varValue)) !== false) {
                    $arrOptions[$intPos] = $arrOption;
                    unset($arrTemp[$i]);
                }
            }
            ksort($arrOptions);
            $this->arrOptions = array_merge($arrOptions, $arrTemp);
        }
        $blnCheckAll = true;
        $arrOptions = array();
        // Generate options and add buttons
        foreach ($this->arrOptions as $i => $arrOption) {
            $arrOptions[] = $this->generateCheckbox($arrOption, $i, '<button class="drag-handle" title="' . \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['move']) . '">' . \Image::getHtml('drag.svg') . '</button> ');
        }
        // Add a "no entries found" message if there are no options
        if (empty($arrOptions)) {
            $arrOptions[] = '<p class="tl_noopt">' . $GLOBALS['TL_LANG']['MSC']['noResult'] . '</p>';
            $blnCheckAll = false;
        }
        return sprintf('<fieldset id="ctrl_%s" class="tl_checkbox_container tl_checkbox_wizard%s"><legend>%s%s%s%s</legend><input type="hidden" name="%s" value="">%s<div class="sortable">%s</div></fieldset>%s<script>Backend.checkboxWizard("ctrl_%s")</script>', $this->strId, $this->strClass != '' ? ' ' . $this->strClass : '', $this->mandatory ? '<span class="invisible">' . $GLOBALS['TL_LANG']['MSC']['mandatory'] . ' </span>' : '', $this->strLabel, $this->mandatory ? '<span class="mandatory">*</span>' : '', $this->xlabel, $this->strName, $blnCheckAll ? '<span class="fixed"><input type="checkbox" id="check_all_' . $this->strId . '" class="tl_checkbox" onclick="Backend.toggleCheckboxGroup(this,\'ctrl_' . $this->strId . '\')"> <label for="check_all_' . $this->strId . '" style="color:#a6a6a6"><em>' . $GLOBALS['TL_LANG']['MSC']['selectAll'] . '</em></label></span>' : '', implode('', $arrOptions), $this->wizard, $this->strId);
    }