Contao\FormSelectMenu::generate PHP Метод

generate() публичный Метод

Generate the widget and return it as string
public generate ( ) : string
Результат string The widget markup
    public function generate()
    {
        $strOptions = '';
        $blnHasGroups = false;
        if ($this->multiple) {
            $this->strName .= '[]';
        } elseif (is_array($this->varValue)) {
            $this->varValue = $this->varValue[0];
        }
        // Add empty option if there are none
        if (empty($this->arrOptions)) {
            $this->arrOptions = array(array('value' => '', 'label' => '-'));
        }
        foreach ($this->arrOptions as $arrOption) {
            if ($arrOption['group']) {
                if ($blnHasGroups) {
                    $strOptions .= '</optgroup>';
                }
                $strOptions .= sprintf('<optgroup label="%s">', \StringUtil::specialchars($arrOption['label']));
                $blnHasGroups = true;
                continue;
            }
            $strOptions .= sprintf('<option value="%s"%s>%s</option>', $arrOption['value'], $this->isSelected($arrOption), $arrOption['label']);
        }
        if ($blnHasGroups) {
            $strOptions .= '</optgroup>';
        }
        return sprintf('<select name="%s" id="ctrl_%s" class="%s"%s>%s</select>', $this->strName, $this->strId, $this->class, $this->getAttributes(), $strOptions);
    }