From ad5980c7aee3085552ec179f6f2513ad43c8933f Mon Sep 17 00:00:00 2001
From: webchick <webchick@24967.no-reply.drupal.org>
Date: Fri, 7 Mar 2014 14:20:52 -0800
Subject: [PATCH] Issue #2152211 by joelpittet, IshaDakota, rteijeiro,
 steveoliver, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ,
 kgoel, Cottser, dsdeiz, hanpersand: Convert theme_form() to Twig.

---
 core/includes/form.inc                       | 12 ++++++------
 core/includes/theme.inc                      |  1 +
 core/modules/system/templates/form.html.twig | 15 +++++++++++++++
 3 files changed, 22 insertions(+), 6 deletions(-)
 create mode 100644 core/modules/system/templates/form.html.twig

diff --git a/core/includes/form.inc b/core/includes/form.inc
index 638f56c25733..886745683ce8 100644
--- a/core/includes/form.inc
+++ b/core/includes/form.inc
@@ -2680,16 +2680,16 @@ function form_pre_render_color($element) {
 }
 
 /**
- * Returns HTML for a form.
+ * Prepares variables for form templates.
+ *
+ * Default template: form.html.twig.
  *
  * @param $variables
  *   An associative array containing:
  *   - element: An associative array containing the properties of the element.
  *     Properties used: #action, #method, #attributes, #children
- *
- * @ingroup themeable
  */
-function theme_form($variables) {
+function template_preprocess_form(&$variables) {
   $element = $variables['element'];
   if (isset($element['#action'])) {
     $element['#attributes']['action'] = UrlHelper::stripDangerousProtocols($element['#action']);
@@ -2698,8 +2698,8 @@ function theme_form($variables) {
   if (empty($element['#attributes']['accept-charset'])) {
     $element['#attributes']['accept-charset'] = "UTF-8";
   }
-  // Anonymous DIV to satisfy XHTML compliance.
-  return '<form' . new Attribute($element['#attributes']) . '><div>' . $element['#children'] . '</div></form>';
+  $variables['attributes'] = $element['#attributes'];
+  $variables['children'] = $element['#children'];
 }
 
 /**
diff --git a/core/includes/theme.inc b/core/includes/theme.inc
index cf9b88038a83..0787de70f8bd 100644
--- a/core/includes/theme.inc
+++ b/core/includes/theme.inc
@@ -2608,6 +2608,7 @@ function drupal_common_theme() {
     ),
     'form' => array(
       'render element' => 'element',
+      'template' => 'form',
     ),
     'textarea' => array(
       'render element' => 'element',
diff --git a/core/modules/system/templates/form.html.twig b/core/modules/system/templates/form.html.twig
new file mode 100644
index 000000000000..b95fe71313c4
--- /dev/null
+++ b/core/modules/system/templates/form.html.twig
@@ -0,0 +1,15 @@
+{#
+/**
+ * @file
+ * Default theme implementation for a 'form' element.
+ *
+ * Available variables
+ * - attributes: A list of HTML attributes for the wrapper element.
+ * - children: The child elements of the form.
+ *
+ * @see template_preprocess_form()
+ *
+ * @ingroup themeable
+ */
+#}
+<form{{ attributes }}><div>{{ children }}</div></form>
-- 
GitLab