commit b88e8f7e768500744e979439b758f553337df030 Author: Pieter Frenssen Date: Fri May 5 16:30:52 2017 +0200 55 diff --git a/core/lib/Drupal/Core/Datetime/Element/Datelist.php b/core/lib/Drupal/Core/Datetime/Element/Datelist.php index c5ecf41549..5ca67ed51e 100644 --- a/core/lib/Drupal/Core/Datetime/Element/Datelist.php +++ b/core/lib/Drupal/Core/Datetime/Element/Datelist.php @@ -302,7 +302,19 @@ public static function processDatelist(&$element, FormStateInterface $form_state public static function validateDatelist(&$element, FormStateInterface $form_state, &$complete_form) { $input_exists = FALSE; $input = NestedArray::getValue($form_state->getValues(), $element['#parents'], $input_exists); - $title = !empty($element['#parents'][0]) ? $element['#parents'][0] : ''; + + $title = ''; + if (!empty($element['#title'])) { + $title = $element['#title']; + } + else { + $parents = $element['#array_parents']; + array_pop($parents); + $parent_element = NestedArray::getValue($complete_form, $parents); + if (!empty($parent_element['#title'])) { + $title = $parent_element['#title']; + } + } if ($input_exists) { $all_empty = static::checkEmptyInputs($input, $element['#date_part_order']); diff --git a/core/modules/datetime/tests/src/Functional/DateTestBase.php b/core/modules/datetime/tests/src/Functional/DateTestBase.php index 369e793343..9127eb25d4 100644 --- a/core/modules/datetime/tests/src/Functional/DateTestBase.php +++ b/core/modules/datetime/tests/src/Functional/DateTestBase.php @@ -107,6 +107,7 @@ protected function setUp() { */ protected function createField() { $field_name = Unicode::strtolower($this->randomMachineName()); + $field_label = Unicode::ucfirst(Unicode::strtolower($this->randomMachineName())); $type = $this->getTestFieldType(); $widget_type = $formatter_type = $type . '_default'; @@ -119,8 +120,9 @@ protected function createField() { $this->fieldStorage->save(); $this->field = FieldConfig::create([ 'field_storage' => $this->fieldStorage, + 'label' => $field_label, 'bundle' => 'entity_test', - 'description' => 'Description for ' . $field_name, + 'description' => 'Description for ' . $field_label, 'required' => TRUE, ]); $this->field->save(); diff --git a/core/modules/datetime/tests/src/Functional/DateTimeFieldTest.php b/core/modules/datetime/tests/src/Functional/DateTimeFieldTest.php index 3eaf25cb7f..3df2582e3e 100644 --- a/core/modules/datetime/tests/src/Functional/DateTimeFieldTest.php +++ b/core/modules/datetime/tests/src/Functional/DateTimeFieldTest.php @@ -208,6 +208,7 @@ public function testDateField() { */ public function testDatetimeField() { $field_name = $this->fieldStorage->getName(); + $field_label = $this->field->label(); // Change the field to a datetime field. $this->fieldStorage->setSetting('datetime_type', 'datetime'); $this->fieldStorage->save(); @@ -216,7 +217,7 @@ public function testDatetimeField() { $this->drupalGet('entity_test/add'); $this->assertFieldByName("{$field_name}[0][value][date]", '', 'Date element found.'); $this->assertFieldByName("{$field_name}[0][value][time]", '', 'Time element found.'); - $this->assertFieldByXPath('//fieldset[@id="edit-' . $field_name . '-0"]/legend', $field_name, 'Fieldset and label found'); + $this->assertFieldByXPath('//fieldset[@id="edit-' . $field_name . '-0"]/legend', $field_label, 'Fieldset and label found'); $this->assertFieldByXPath('//fieldset[@aria-describedby="edit-' . $field_name . '-0--description"]', NULL, 'ARIA described-by found'); $this->assertFieldByXPath('//div[@id="edit-' . $field_name . '-0--description"]', NULL, 'ARIA description found'); @@ -352,6 +353,7 @@ public function testDatetimeField() { */ public function testDatelistWidget() { $field_name = $this->fieldStorage->getName(); + $field_label = $this->field->label(); // Ensure field is set to a date only field. $this->fieldStorage->setSetting('datetime_type', 'date'); @@ -370,7 +372,7 @@ public function testDatelistWidget() { // Display creation form. $this->drupalGet('entity_test/add'); - $this->assertFieldByXPath('//fieldset[@id="edit-' . $field_name . '-0"]/legend', $field_name, 'Fieldset and label found'); + $this->assertFieldByXPath('//fieldset[@id="edit-' . $field_name . '-0"]/legend', $field_label, 'Fieldset and label found'); $this->assertFieldByXPath('//fieldset[@aria-describedby="edit-' . $field_name . '-0--description"]', NULL, 'ARIA described-by found'); $this->assertFieldByXPath('//div[@id="edit-' . $field_name . '-0--description"]', NULL, 'ARIA description found'); @@ -511,7 +513,7 @@ public function testDatelistWidget() { \Drupal::entityManager()->clearCachedFieldDefinitions(); // Test the widget for validation notifications. - foreach ($this->datelistDataProvider($field_name) as $data) { + foreach ($this->datelistDataProvider($field_label) as $data) { list($date_value, $expected) = $data; // Display creation form. @@ -562,21 +564,21 @@ public function testDatelistWidget() { /** * The data provider for testing the validation of the datelist widget. * - * @param string $field_name - * The name of the field being tested. + * @param string $field_label + * The label of the field being tested. * * @return array * An array of datelist input permutations to test. */ - protected function datelistDataProvider($field_name) { + protected function datelistDataProvider($field_label) { return [ // Nothing selected. [['year' => '', 'month' => '', 'day' => '', 'hour' => '', 'minute' => ''], [ - "The {$field_name} date is required", + "The $field_label date is required.", ]], // Year only selected, validation error on Month, Day, Hour, Minute. [['year' => 2012, 'month' => '', 'day' => '', 'hour' => '', 'minute' => ''], [ - "The {$field_name} date is incomplete.", + "The $field_label date is incomplete.", 'A value must be selected for month.', 'A value must be selected for day.', 'A value must be selected for hour.', @@ -584,20 +586,20 @@ protected function datelistDataProvider($field_name) { ]], // Year and Month selected, validation error on Day, Hour, Minute. [['year' => 2012, 'month' => '12', 'day' => '', 'hour' => '', 'minute' => ''], [ - "The {$field_name} date is incomplete.", + "The $field_label date is incomplete.", 'A value must be selected for day.', 'A value must be selected for hour.', 'A value must be selected for minute.', ]], // Year, Month and Day selected, validation error on Hour, Minute. [['year' => 2012, 'month' => '12', 'day' => '31', 'hour' => '', 'minute' => ''], [ - "The {$field_name} date is incomplete.", + "The $field_label date is incomplete.", 'A value must be selected for hour.', 'A value must be selected for minute.', ]], // Year, Month, Day and Hour selected, validation error on Minute only. [['year' => 2012, 'month' => '12', 'day' => '31', 'hour' => '0', 'minute' => ''], [ - "The {$field_name} date is incomplete.", + "The $field_label date is incomplete.", 'A value must be selected for minute.', ]], ];