summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwebchick2014-03-07 13:51:16 -0800
committerwebchick2014-03-07 13:51:16 -0800
commit82bb0f33fff1464c3b4ce69a9f2ef3465126a9ae (patch)
treea1ae2db525668908cf9681adece34846a5cff8bc
parentb6ffa568fed9f43e5ee6419705f5b727e697e302 (diff)
Issue #2152225 by longwave, JeroenT, steveoliver, joelpittet, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_select() to Twig
-rw-r--r--core/includes/form.inc11
-rw-r--r--core/includes/theme.inc1
-rw-r--r--core/modules/system/templates/select.html.twig15
3 files changed, 22 insertions, 5 deletions
diff --git a/core/includes/form.inc b/core/includes/form.inc
index 20edb53..638f56c 100644
--- a/core/includes/form.inc
+++ b/core/includes/form.inc
@@ -876,7 +876,9 @@ function form_process_select($element) {
}
/**
- * Returns HTML for a select form element.
+ * Prepares variables for select element templates.
+ *
+ * Default template: select.html.twig.
*
* It is possible to group options together; to do this, change the format of
* $options to an associative array in which the keys are group labels, and the
@@ -887,15 +889,14 @@ function form_process_select($element) {
* - element: An associative array containing the properties of the element.
* Properties used: #title, #value, #options, #description, #extra,
* #multiple, #required, #name, #attributes, #size.
- *
- * @ingroup themeable
*/
-function theme_select($variables) {
+function template_preprocess_select(&$variables) {
$element = $variables['element'];
element_set_attributes($element, array('id', 'name', 'size'));
_form_set_attributes($element, array('form-select'));
- return '<select' . new Attribute($element['#attributes']) . '>' . form_select_options($element) . '</select>';
+ $variables['attributes'] = $element['#attributes'];
+ $variables['options'] = form_select_options($element);
}
/**
diff --git a/core/includes/theme.inc b/core/includes/theme.inc
index 435b9da..e35ef01 100644
--- a/core/includes/theme.inc
+++ b/core/includes/theme.inc
@@ -2591,6 +2591,7 @@ function drupal_common_theme() {
),
'select' => array(
'render element' => 'element',
+ 'template' => 'select',
),
'fieldset' => array(
'render element' => 'element',
diff --git a/core/modules/system/templates/select.html.twig b/core/modules/system/templates/select.html.twig
new file mode 100644
index 0000000..21f32ac
--- /dev/null
+++ b/core/modules/system/templates/select.html.twig
@@ -0,0 +1,15 @@
+{#
+/**
+ * @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
+ */
+#}
+<select{{ attributes }}>{{ options }}</select>