Security update for Core, with self-updated composer
[yaffs-website] / web / core / lib / Drupal / Core / Form / FormValidator.php
index 7398053bc68d792a5a33a3d2e71a059ccf2f7394..8e976f5a86060ab79324c7f4d5969914b2564579 100644 (file)
@@ -229,8 +229,12 @@ class FormValidator implements FormValidatorInterface {
    *   theming, and hook_form_alter functions.
    */
   protected function doValidateForm(&$elements, FormStateInterface &$form_state, $form_id = NULL) {
-    // Recurse through all children.
-    foreach (Element::children($elements) as $key) {
+    // Recurse through all children, sorting the elements so that the order of
+    // error messages displayed to the user matches the order of elements in
+    // the form. Use a copy of $elements so that it is not modified by the
+    // sorting itself.
+    $elements_sorted = $elements;
+    foreach (Element::children($elements_sorted, TRUE) as $key) {
       if (isset($elements[$key]) && $elements[$key]) {
         $this->doValidateForm($elements[$key], $form_state);
       }