diff --git a/core/lib/Drupal/Core/Form/FormErrorHandler.php b/core/lib/Drupal/Core/Form/FormErrorHandler.php index d8bf7d0..075c53d 100644 --- a/core/lib/Drupal/Core/Form/FormErrorHandler.php +++ b/core/lib/Drupal/Core/Form/FormErrorHandler.php @@ -77,7 +77,7 @@ protected function displayErrorMessages(FormStateInterface $form_state) { $title = FormElementHelper::getElementTitle($form_element); // Only show links to erroneous elements that are visible - $is_visible_element = Element::isVisibleElement($form_element) ? TRUE : FALSE; + $is_visible_element = Element::isVisibleElement($form_element); // 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 diff --git a/core/lib/Drupal/Core/Render/Element.php b/core/lib/Drupal/Core/Render/Element.php index bff998c..73eefda 100644 --- a/core/lib/Drupal/Core/Render/Element.php +++ b/core/lib/Drupal/Core/Render/Element.php @@ -162,7 +162,7 @@ public static function getVisibleChildren(array $elements) { * TRUE if the element is visible, otherwise FALSE. */ public static function isVisibleElement($element) { - return !isset($element['#type']) || !in_array($element['#type'], ['value', 'hidden', 'token']); + return (!isset($element['#type']) || !in_array($element['#type'], ['value', 'hidden', 'token'])) && (!isset($element['#access']) || $element['#access']); } /** diff --git a/core/modules/file/src/Element/ManagedFile.php b/core/modules/file/src/Element/ManagedFile.php index 4c70ef1..0c0d17d 100644 --- a/core/modules/file/src/Element/ManagedFile.php +++ b/core/modules/file/src/Element/ManagedFile.php @@ -233,6 +233,7 @@ public static function processManagedFile(&$element, FormStateInterface $form_st '#multiple' => $element['#multiple'], '#theme_wrappers' => [], '#weight' => -10, + '#error_use_parent' => TRUE, ]; if (!empty($fids) && $element['#files']) { diff --git a/core/modules/file/src/Tests/FileFieldValidateTest.php b/core/modules/file/src/Tests/FileFieldValidateTest.php index ea8c0c9..d31ef09 100644 --- a/core/modules/file/src/Tests/FileFieldValidateTest.php +++ b/core/modules/file/src/Tests/FileFieldValidateTest.php @@ -34,7 +34,7 @@ function testRequired() { $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: ' . $field->label(), '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 @@ function testRequired() { $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: ' . $field->label(), '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.