concrete/src/Form/Service/Form.php
public function select($key, $optionValues, $valueOrMiscFields = '', $miscFields = [])
    {
        if (!is_array($optionValues)) {
            $optionValues = [];
        }
        if (is_array($valueOrMiscFields)) {
            $selectedValue = '';
            $miscFields = $valueOrMiscFields;
        } else {
            $selectedValue = (string) $valueOrMiscFields;
        }
        if ($selectedValue !== '') {
            $miscFields['ccm-passed-value'] = h($selectedValue);
        }
        $requestValue = $this->getRequestValue($key);
        if (is_array($requestValue) && isset($requestValue[0]) && is_string($requestValue[0])) {
            $selectedValue = (string) $requestValue[0];
        } elseif ($requestValue !== false) {
            if (!is_array($requestValue)) {
                $selectedValue = (string) $requestValue;
            } else {
                $selectedValue = '';
            }
        }
        if (substr($key, -2) == '[]') {
            $_key = substr($key, 0, -2);
            $id = $_key . $this->selectIndex;
            ++$this->selectIndex;
        } else {
            $id = $key;
        }
        $str = '<select id="' . $id . '" name="' . $key . '"' . $this->parseMiscFields('form-control', $miscFields) . '>';
        foreach ($optionValues as $k => $text) {
            if (is_array($text)) {
                $str .= '<optgroup label="' . h($k) . '">';
                foreach ($text as $optionValue => $optionText) {
                    $str .= '<option value="' . h($optionValue) . '"';
                    if ((string) $optionValue === (string) $selectedValue) {
                        $str .= ' selected="selected"';
                    }
                    $str .= '>' . h($optionText) . '</option>';
                }
                $str .= '</optgroup>';
            } else {
                $str .= '<option value="' . h($k) . '"';
                if ((string) $k === (string) $selectedValue) {
                    $str .= ' selected="selected"';
                }
                $str .= '>' . $text . '</option>';
            }
        }
        $str .= '</select>';

        return $str;
    }
public function select($key, $optionValues, $valueOrMiscFields = '', $miscFields = [])
    {
        if (!is_array($optionValues)) {
            $optionValues = [];
        }
        if (is_array($valueOrMiscFields)) {
            $selectedValue = '';
            $miscFields = $valueOrMiscFields;
        } else {
            $selectedValue = (string) $valueOrMiscFields;
        }
        if ($selectedValue !== '') {
            $miscFields['ccm-passed-value'] = h($selectedValue);
        }
        $requestValue = $this->getRequestValue($key);
        if (is_array($requestValue) && isset($requestValue[0]) && is_string($requestValue[0])) {
            $selectedValue = (string) $requestValue[0];
        } elseif ($requestValue !== false) {
            if (!is_array($requestValue)) {
                $selectedValue = (string) $requestValue;
            } else {
                $selectedValue = '';
            }
        }
        if (substr($key, -2) == '[]') {
            $_key = substr($key, 0, -2);
            $id = $_key . $this->selectIndex;
            ++$this->selectIndex;
        } else {
            $id = $key;
        }
        $str = '<select id="' . $id . '" name="' . $key . '"' . $this->parseMiscFields('form-control', $miscFields) . '>';
        foreach ($optionValues as $k => $text) {
            if (is_array($text)) {
                $str .= '<optgroup label="' . h($k) . '">';
                foreach ($text as $optionValue => $optionText) {
                    $str .= '<option value="' . h($optionValue) . '"';
                    if ((string) $optionValue === (string) $selectedValue) {
                        $str .= ' selected="selected"';
                    }
                    $str .= '>' . h($optionText) . '</option>';
                }
                $str .= '</optgroup>';
            } else {
                $str .= '<option value="' . h($k) . '"';
                if ((string) $k === (string) $selectedValue) {
                    $str .= ' selected="selected"';
                }
                $str .= '>' . $text . '</option>';
            }
        }
        $str .= '</select>';

        return $str;
    }
public function select ( $ key , $ optionValues , $ valueOrMiscFields = '' , $ miscFields = [ ] ) { if ( ! is_array ( $ optionValues ) ) { $ optionValues = [ ] ; } if ( is_array ( $ valueOrMiscFields ) ) { $ selectedValue = '' ; $ miscFields = $ valueOrMiscFields ; } else { $ selectedValue = ( string ) $ valueOrMiscFields ; } if ( $ selectedValue !== '' ) { $ miscFields [ 'ccm-passed-value' ] = h ( $ selectedValue ) ; } $ requestValue = $ this -> getRequestValue ( $ key ) ; if ( is_array ( $ requestValue ) && isset ( $ requestValue [ 0 ] ) && is_string ( $ requestValue [ 0 ] ) ) { $ selectedValue = ( string ) $ requestValue [ 0 ] ; } elseif ( $ requestValue !== false ) { if ( ! is_array ( $ requestValue ) ) { $ selectedValue = ( string ) $ requestValue ; } else { $ selectedValue = '' ; } } if ( substr ( $ key , - 2 ) == '[]' ) { $ _key = substr ( $ key , 0 , - 2 ) ; $ id = $ _key . $ this -> selectIndex ; ++ $ this -> selectIndex ; } else { $ id = $ key ; } $ str = '<select id="' . $ id . '" name="' . $ key . '"' . $ this -> parseMiscFields ( 'form-control' , $ miscFields ) . '>' ; foreach ( $ optionValues as $ k => $ text ) { if ( is_array ( $ text ) ) { $ str .= '<optgroup label="' . h ( $ k ) . '">' ; foreach ( $ text as $ optionValue => $ optionText ) { $ str .= '<option value="' . h ( $ optionValue ) . '"' ; if ( ( string ) $ optionValue === ( string ) $ selectedValue ) { $ str .= ' selected="selected"' ; } $ str .= '>' . h ( $ optionText ) . '</option>' ; } $ str .= '</optgroup>' ; } else { $ str .= '<option value="' . h ( $ k ) . '"' ; if ( ( string ) $ k === ( string ) $ selectedValue ) { $ str .= ' selected="selected"' ; } $ str .= '>' . $ text . '</option>' ; } } $ str .= '</select>' ; return $ str ; }
Renders a select field.

@param string $key The name of the element. If $key denotes an array, the ID will start with $key but will have a progressive unique number added; if $key does not denotes an array, the ID attribute will be $key.
@param array $optionValues an associative array of key => display
@param string|array $valueOrMiscFields the value of the field to be selected or an array with additional fields appended to the element (a hash array of attributes name => value), possibly including 'class'
@param array $miscFields (used if $valueOrMiscFields is not an array) Additional fields appended to the element (a hash array of attributes name => value), possibly including 'class'

@return $html
Renders a select field .