diff --git a/templates/form/select.html.twig b/templates/form/select.html.twig new file mode 100644 index 0000000000000000000000000000000000000000..4042ab97d9af9e7ecf98809daadf00d568f62068 --- /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 + */ +#} + {# look at the options array and if < 4 then use for the size attribute #} + {% if options|length < 4 %} + {% set select_size = options|length %} + {% endif %} + +{% apply spaceless %} + <select{{ attributes.setAttribute('size', select_size) }}> + {% 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 %}