From fba3f3634b84f9d7c32e11126d4489a7989362bc Mon Sep 17 00:00:00 2001
From: Martin Leblanc <m26lebla@uwaterloo.ca>
Date: Tue, 22 Nov 2022 12:57:28 -0500
Subject: [PATCH] ISTWCMS-5946: adding logic to add size to attributes array
 when options are less than 4 in multiple select

---
 templates/form/select.html.twig | 34 +++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
 create mode 100644 templates/form/select.html.twig

diff --git a/templates/form/select.html.twig b/templates/form/select.html.twig
new file mode 100644
index 00000000..4042ab97
--- /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 %}
-- 
GitLab