diff --git a/core/lib/Drupal/Core/Render/Element/Details.php b/core/lib/Drupal/Core/Render/Element/Details.php index ae25d345ace95799192d6dc70d913b6592b7a28f..2ae6f1d8ef7127928993160a5d24b67ed67b7e84 100644 --- a/core/lib/Drupal/Core/Render/Element/Details.php +++ b/core/lib/Drupal/Core/Render/Element/Details.php @@ -75,7 +75,9 @@ public static function preRenderDetails($element) { // Collapsible details. $element['#attached']['library'][] = 'core/drupal.collapse'; - if (!empty($element['#open'])) { + + // Open the detail if specified or if a child has an error. + if (!empty($element['#open']) || !empty($element['#children_errors'])) { $element['#attributes']['open'] = 'open'; } diff --git a/core/modules/node/src/Tests/NodeEditFormTest.php b/core/modules/node/src/Tests/NodeEditFormTest.php index 0d6bf45fd25873ce15caa823d2877e9eace87bd8..bef0252cc02d59c685624f25058234ef0f59acaa 100644 --- a/core/modules/node/src/Tests/NodeEditFormTest.php +++ b/core/modules/node/src/Tests/NodeEditFormTest.php @@ -115,6 +115,21 @@ public function testNodeEdit() { // Check if the node revision checkbox is rendered on node edit form. $this->drupalGet('node/' . $node->id() . '/edit'); $this->assertFieldById('edit-revision', NULL, 'The revision field is present.'); + + // Check that details form element opens when there are errors on child + // elements. + $this->drupalGet('node/' . $node->id() . '/edit'); + $edit = []; + // This invalid date will trigger an error. + $edit['created[0][value][date]'] = $this->randomMachineName(8); + // Get the current amount of open details elements. + $open_details_elements = count($this->cssSelect('details[open="open"]')); + $this->drupalPostForm(NULL, $edit, t('Save and keep published')); + // The node author details must be open. + $this->assertRaw('
'); + // Only one extra details element should now be open. + $open_details_elements++; + $this->assertEqual(count($this->cssSelect('details[open="open"]')), $open_details_elements, 'Exactly one extra open <details> element found.'); } /**