diff --git a/templates/form/select.html.twig b/templates/form/select.html.twig new file mode 100644 index 0000000000000000000000000000000000000000..18ce6dd3b0a024ec69783f2191ac44f625eff237 --- /dev/null +++ b/templates/form/select.html.twig @@ -0,0 +1,34 @@ +{# +/** + * @file + * Default theme implementation for a select element. + * + * Available variables: + * - attributes: HTML attributes for the <select> tag. + * - options: The <option> element children. + * + * @see template_preprocess_select() + * + * @ingroup themeable + */ +#} +{# if size is not set, look at the options array and if < 4 then use for the size attribute #} +{% if not attributes.size and options|length < 4 %} + {% set attributes = attributes.setAttribute('size', options|length) %} +{% endif %} + +{% apply spaceless %} + <select{{ attributes }}> + {% for option in options %} + {% if option.type == 'optgroup' %} + <optgroup label="{{ option.label }}"> + {% for sub_option in option.options %} + <option value="{{ sub_option.value }}"{{ sub_option.selected ? ' selected="selected"' }}>{{ sub_option.label }}</option> + {% endfor %} + </optgroup> + {% elseif option.type == 'option' %} + <option value="{{ option.value }}"{{ option.selected ? ' selected="selected"' }}>{{ option.label }}</option> + {% endif %} + {% endfor %} + </select> +{% endapply %}