Skip to content
Snippets Groups Projects
Commit fba3f363 authored by Martin Leblanc's avatar Martin Leblanc
Browse files

ISTWCMS-5946: adding logic to add size to attributes array when options are...

ISTWCMS-5946: adding logic to add size to attributes array when options are less than 4 in multiple select
parent 9d9390a5
No related branches found
No related tags found
1 merge request!88ISTWCMS-5946: adding twig logic to add size to attributes array for select
{#
/**
* @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 %}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment