From c76edb49d9ee31584f247cd3ea8cc7871685efb0 Mon Sep 17 00:00:00 2001
From: skaught <skaught@gmail.com>
Date: Mon, 25 Jul 2016 20:16:53 -0400
Subject: [PATCH] test1

---
 core/includes/theme.inc                            |  6 +++
 core/modules/system/src/Tests/Form/ElementTest.php | 11 ++++-
 core/modules/system/templates/container.html.twig  | 10 ++++-
 .../tests/modules/form_test/form_test.routing.yml  |  8 ++++
 .../form_test/src/Form/FormTestContainerForm.php   | 51 ++++++++++++++++++++++
 .../form_test/src/Form/FormTestDetailsForm.php     |  2 +-
 .../tests/src/Kernel/Plugin/StyleMappingTest.php   |  4 +-
 .../Core/Render/Element/RenderElementTypesTest.php |  6 +--
 .../classy/templates/form/container.html.twig      | 10 ++++-
 9 files changed, 98 insertions(+), 10 deletions(-)
 create mode 100644 core/modules/system/tests/modules/form_test/src/Form/FormTestContainerForm.php

diff --git a/core/includes/theme.inc b/core/includes/theme.inc
index 9b89250..20fc1f2 100644
--- a/core/includes/theme.inc
+++ b/core/includes/theme.inc
@@ -1146,6 +1146,12 @@ function template_preprocess_container(&$variables) {
 
   $variables['children'] = $element['#children'];
   $variables['attributes'] = $element['#attributes'];
+
+  // Display any error messages.
+  $variables['errors'] = NULL;
+  if (!empty($element['#errors']) && empty($element['#error_no_message'])) {
+   $variables['errors'] = $element['#errors'];
+  }
 }
 
 /**
diff --git a/core/modules/system/src/Tests/Form/ElementTest.php b/core/modules/system/src/Tests/Form/ElementTest.php
index 684e13a..0ff443f 100644
--- a/core/modules/system/src/Tests/Form/ElementTest.php
+++ b/core/modules/system/src/Tests/Form/ElementTest.php
@@ -162,11 +162,18 @@ public function testFormAutocomplete() {
   }
 
   /**
-   * Tests form element error messages.
+   * Tests form details element error messages.
    */
-  public function testFormElementErrors() {
+  public function testFormDetailsErrors() {
     $this->drupalPostForm('form_test/details-form', [], 'Submit');
     $this->assertText('I am an error on the details element.');
   }
+  /**
+   * Tests form container element error messages.
+   */
+  public function testFormElementErrors() {
+    $this->drupalPostForm('form_test/container-form', [], 'Submit');
+    $this->assertText('I am an error on the container element.');
+  }
 
 }
diff --git a/core/modules/system/templates/container.html.twig b/core/modules/system/templates/container.html.twig
index 6cb299b..02fe98c 100644
--- a/core/modules/system/templates/container.html.twig
+++ b/core/modules/system/templates/container.html.twig
@@ -12,6 +12,7 @@
  *
  * Available variables:
  * - attributes: HTML attributes for the containing element.
+ * - errors: (optional) Any errors for this container element, may not be set.
  * - children: The rendered child elements of the container.
  * - has_parent: A flag to indicate that the container has one or more parent
      containers.
@@ -27,4 +28,11 @@
     has_parent ? 'form-wrapper',
   ]
 %}
-<div{{ attributes.addClass(classes) }}>{{ children }}</div>
+<div{{ attributes.addClass(classes) }}>
+{% if errors %}
+  <div>
+    {{ errors }}
+  </div>
+{% endif %}
+{{ children }}
+</div>
diff --git a/core/modules/system/tests/modules/form_test/form_test.routing.yml b/core/modules/system/tests/modules/form_test/form_test.routing.yml
index 42a6ba4..327d7fd 100644
--- a/core/modules/system/tests/modules/form_test/form_test.routing.yml
+++ b/core/modules/system/tests/modules/form_test/form_test.routing.yml
@@ -409,6 +409,14 @@ form_test.details_form:
   requirements:
     _access: 'TRUE'
 
+form_test.container_form:
+  path: '/form_test/container-form'
+  defaults:
+    _form: '\Drupal\form_test\Form\FormTestContainerForm'
+    _title: 'Form contaner form test'
+  requirements:
+    _access: 'TRUE'
+
 form_test.description_display:
   path: '/form_test/form-descriptions'
   defaults:
diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestContainerForm.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestContainerForm.php
new file mode 100644
index 0000000..e013484
--- /dev/null
+++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestContainerForm.php
@@ -0,0 +1,51 @@
+<?php
+
+namespace Drupal\form_test\Form;
+
+use Drupal\Core\Form\FormBase;
+use Drupal\Core\Form\FormStateInterface;
+
+/**
+ * Builds a simple form to test the #group property on #type 'container'.
+ */
+class FormTestContainerForm extends FormBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getFormId() {
+    return 'form_test_container_form';
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function buildForm(array $form, FormStateInterface $form_state) {
+    $form['meta'] = [
+      '#type' => 'container',
+      '#attributes' => array(
+        'class' => 'accommodation',
+      ),
+    ];
+    $form['meta']['child'] = [
+      '#type' => 'textfield',
+      '#title' => 'a textfield in a container',
+    ];
+    $form['submit'] = ['#type' => 'submit', '#value' => 'Submit'];
+    return $form;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function validateForm(array &$form, FormStateInterface $form_state) {
+    $form_state->setErrorByName('meta', 'I am an error on the container element.');
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function submitForm(array &$form, FormStateInterface $form_state) {
+  }
+
+}
diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestDetailsForm.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestDetailsForm.php
index 5949679..55fcbfd 100644
--- a/core/modules/system/tests/modules/form_test/src/Form/FormTestDetailsForm.php
+++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestDetailsForm.php
@@ -6,7 +6,7 @@
 use Drupal\Core\Form\FormStateInterface;
 
 /**
- * Builds a simple form to test the #group property on #type 'container'.
+ * Builds a simple form to test the #group property on #type 'details'.
  */
 class FormTestDetailsForm extends FormBase {
 
diff --git a/core/modules/views/tests/src/Kernel/Plugin/StyleMappingTest.php b/core/modules/views/tests/src/Kernel/Plugin/StyleMappingTest.php
index 1cb4400..e5f6904 100644
--- a/core/modules/views/tests/src/Kernel/Plugin/StyleMappingTest.php
+++ b/core/modules/views/tests/src/Kernel/Plugin/StyleMappingTest.php
@@ -66,8 +66,8 @@ protected function mappedOutputHelper($view) {
 
         // The expected result is the mapping name and the field value,
         // separated by ':'.
-        $expected_result = $name . ':' . $data_set[$count][$field_id];
-        $actual_result = (string) $field;
+        $expected_result = str_replace(array('\n', '\r'), '', $name . ':' . $data_set[$count][$field_id]);
+        $actual_result = str_replace(array('\n', '\r'), '', (string) $field);
         $this->assertIdentical($expected_result, $actual_result, format_string('The fields were mapped successfully: %name => %field_id', array('%name' => $name, '%field_id' => $field_id)));
       }
 
diff --git a/core/tests/Drupal/KernelTests/Core/Render/Element/RenderElementTypesTest.php b/core/tests/Drupal/KernelTests/Core/Render/Element/RenderElementTypesTest.php
index 3e11695..97c56c0 100644
--- a/core/tests/Drupal/KernelTests/Core/Render/Element/RenderElementTypesTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Render/Element/RenderElementTypesTest.php
@@ -56,7 +56,7 @@ function testContainer() {
     $this->assertElements(array(
       '#type' => 'container',
       '#markup' => 'foo',
-    ), "<div>foo</div>\n", "#type 'container' with no HTML attributes");
+    ), "<div>\nfoo\n</div>\n", "#type 'container' with no HTML attributes");
 
     // Container with a class.
     $this->assertElements(array(
@@ -65,7 +65,7 @@ function testContainer() {
       '#attributes' => array(
         'class' => array('bar'),
       ),
-    ), '<div class="bar">foo</div>' . "\n", "#type 'container' with a class HTML attribute");
+    ), '<div class="bar">' . "\n" . 'foo' . "\n" . '</div>' . "\n", "#type 'container' with a class HTML attribute");
 
     // Container with children.
     $this->assertElements(array(
@@ -73,7 +73,7 @@ function testContainer() {
       'child' => array(
         '#markup' => 'foo',
       ),
-    ), "<div>foo</div>\n", "#type 'container' with child elements");
+    ), "<div>\nfoo\n</div>\n", "#type 'container' with child elements");
   }
 
   /**
diff --git a/core/themes/classy/templates/form/container.html.twig b/core/themes/classy/templates/form/container.html.twig
index 0da6c38..caafe73 100644
--- a/core/themes/classy/templates/form/container.html.twig
+++ b/core/themes/classy/templates/form/container.html.twig
@@ -12,6 +12,7 @@
  *
  * Available variables:
  * - attributes: HTML attributes for the containing element.
+ * - errors: (optional) Any errors for this container element, may not be set.
  * - children: The rendered child elements of the container.
  * - has_parent: A flag to indicate that the container has one or more parent
      containers.
@@ -25,4 +26,11 @@
     has_parent ? 'form-wrapper',
   ]
 %}
-<div{{ attributes.addClass(classes) }}>{{ children }}</div>
+<div{{ attributes.addClass(classes) }}>
+{% if errors %}
+  <div class="form-item--error-message">
+    <strong>{{ errors }}</strong>
+  </div>
+{% endif %}
+{{ children }}
+</div>
-- 
2.6.4

