diff -u b/core/lib/Drupal/Core/Form/FormErrorHandler.php b/core/lib/Drupal/Core/Form/FormErrorHandler.php --- b/core/lib/Drupal/Core/Form/FormErrorHandler.php +++ b/core/lib/Drupal/Core/Form/FormErrorHandler.php @@ -76,13 +76,15 @@ foreach ($this->errorLinkElements as $form_element) { $title = FormElementHelper::getElementTitle($form_element); - // Only show links to erroneous elements that are visible + // Only show links to erroneous elements that are visible. $is_visible_element = Element::isVisibleElement($form_element) ? TRUE : FALSE; - // And don't show links to elements which use their parent element for inline errors + // And don't show links to elements which use their parent element for + // inline errors. $not_use_parent = empty($form_element['#error_use_parent']); - // And only show links for elements that have a title themselves or have children with a title + // And only show links for elements that have a title themselves or have + // children with a title. $has_title = !empty($title); - // And only show links for elements with an id + // And only show links for elements with an ID. $has_id = !empty($form_element['#id']); if ($is_visible_element && $not_use_parent && $has_title && $has_id) { @@ -94,7 +96,7 @@ } } - // For all left over errors set normal error messages + // For all left over errors set normal error messages. foreach ($errors as $error) { $this->drupalSetMessage($error, 'error'); } @@ -116,7 +118,7 @@ } /** - * Stores the errors of each element directly on the element and keep a list + * Stores the errors of each element directly on the element and keeps a list * of these elements * * We must provide a way for non-form functions to check the errors for a diff -u b/core/modules/file/src/Element/ManagedFile.php b/core/modules/file/src/Element/ManagedFile.php --- b/core/modules/file/src/Element/ManagedFile.php +++ b/core/modules/file/src/Element/ManagedFile.php @@ -232,6 +232,8 @@ '#size' => $element['#size'], '#multiple' => $element['#multiple'], '#theme_wrappers' => [], + // Errors should only be shown on the parent element. + '#error_use_parent' => TRUE, '#weight' => -10, ]; diff -u b/core/modules/file/src/Tests/FileFieldValidateTest.php b/core/modules/file/src/Tests/FileFieldValidateTest.php --- b/core/modules/file/src/Tests/FileFieldValidateTest.php +++ b/core/modules/file/src/Tests/FileFieldValidateTest.php @@ -34,7 +34,7 @@ $edit = array(); $edit['title[0][value]'] = $this->randomMachineName(); $this->drupalPostForm('node/add/' . $type_name, $edit, t('Save and publish')); - $this->assertText('1 error has been found: Choose a file', 'Node save failed when required file field was empty.'); + $this->assertText('1 error has been found: ' . $edit['title[0][value]'], 'Node save failed when required file field was empty.'); $this->assertIdentical(1, count($this->xpath('//div[contains(concat(" ", normalize-space(@class), " "), :class)]//a', array(':class' => ' messages--error '))), 'There is one link in the error message.'); // Create a new node with the uploaded file. @@ -56,7 +56,7 @@ $edit = array(); $edit['title[0][value]'] = $this->randomMachineName(); $this->drupalPostForm('node/add/' . $type_name, $edit, t('Save and publish')); - $this->assertText('1 error has been found: Choose a file', 'Node save failed when required multiple value file field was empty.'); + $this->assertText('1 error has been found: ' . $edit['title[0][value]'], 'Node save failed when required multiple value file field was empty.'); $this->assertIdentical(1, count($this->xpath('//div[contains(concat(" ", normalize-space(@class), " "), :class)]//a', array(':class' => ' messages--error '))), 'There is one link in the error message.'); // Create a new node with the uploaded file into the multivalue field.