diff --git a/core/lib/Drupal/Core/Datetime/Element/Datelist.php b/core/lib/Drupal/Core/Datetime/Element/Datelist.php index 59177e7..addbf34 100644 --- a/core/lib/Drupal/Core/Datetime/Element/Datelist.php +++ b/core/lib/Drupal/Core/Datetime/Element/Datelist.php @@ -311,7 +311,7 @@ public static function validateDatelist(&$element, FormStateInterface $form_stat } // If there's empty input and the field is required, set an error. elseif (empty($input['year']) && empty($input['month']) && empty($input['day']) && $element['#required']) { - $form_state->setError($element, t('The %field date is required.')); + $form_state->setError($element, t('The %field date is required.', ['%field' => !empty($element['#title']) ? $element['#title'] : ''])); } elseif (!empty($all_empty)) { foreach ($all_empty as $value) { diff --git a/core/modules/datetime/tests/src/Functional/DateTimeFieldTest.php b/core/modules/datetime/tests/src/Functional/DateTimeFieldTest.php index ab03ff5..96b63d6 100644 --- a/core/modules/datetime/tests/src/Functional/DateTimeFieldTest.php +++ b/core/modules/datetime/tests/src/Functional/DateTimeFieldTest.php @@ -722,6 +722,7 @@ public function testInvalidField() { $this->fieldStorage->setSetting('datetime_type', 'datetime'); $this->fieldStorage->save(); $field_name = $this->fieldStorage->getName(); + $field_label = $this->field->getLabel(); // Display creation form. $this->drupalGet('entity_test/add'); @@ -735,7 +736,7 @@ public function testInvalidField() { "{$field_name}[0][value][time]" => '12:00:00', ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('date is invalid', 'Empty date value has been caught.'); + $this->assertText(format_string('The @field_name date is invalid', ['@field_name' => $field_label]), 'Empty date value has been caught.'); $date_value = 'aaaa-12-01'; $edit = [ @@ -743,7 +744,7 @@ public function testInvalidField() { "{$field_name}[0][value][time]" => '00:00:00', ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('date is invalid', format_string('Invalid year value %date has been caught.', ['%date' => $date_value])); + $this->assertText(format_string('The @field_name date is invalid', ['@field_name' => $field_label]), format_string('Invalid year value %date has been caught.', ['%date' => $date_value])); $date_value = '2012-75-01'; $edit = [ @@ -751,7 +752,7 @@ public function testInvalidField() { "{$field_name}[0][value][time]" => '00:00:00', ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('date is invalid', format_string('Invalid month value %date has been caught.', ['%date' => $date_value])); + $this->assertText(format_string('The @field_name date is invalid', ['@field_name' => $field_label]), format_string('Invalid month value %date has been caught.', ['%date' => $date_value])); $date_value = '2012-12-99'; $edit = [ @@ -759,7 +760,7 @@ public function testInvalidField() { "{$field_name}[0][value][time]" => '00:00:00', ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('date is invalid', format_string('Invalid day value %date has been caught.', ['%date' => $date_value])); + $this->assertText(format_string('The @field_name date is invalid', ['@field_name' => $field_label]), format_string('Invalid day value %date has been caught.', ['%date' => $date_value])); $date_value = '2012-12-01'; $time_value = ''; @@ -768,7 +769,7 @@ public function testInvalidField() { "{$field_name}[0][value][time]" => $time_value, ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('date is invalid', 'Empty time value has been caught.'); + $this->assertText(format_string('The @field_name date is invalid', ['@field_name' => $field_label]), 'Empty time value has been caught.'); $date_value = '2012-12-01'; $time_value = '49:00:00'; @@ -777,7 +778,7 @@ public function testInvalidField() { "{$field_name}[0][value][time]" => $time_value, ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('date is invalid', format_string('Invalid hour value %time has been caught.', ['%time' => $time_value])); + $this->assertText(format_string('The @field_name date is invalid', ['@field_name' => $field_label]), format_string('Invalid hour value %time has been caught.', ['%time' => $time_value])); $date_value = '2012-12-01'; $time_value = '12:99:00'; @@ -786,7 +787,7 @@ public function testInvalidField() { "{$field_name}[0][value][time]" => $time_value, ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('date is invalid', format_string('Invalid minute value %time has been caught.', ['%time' => $time_value])); + $this->assertText(format_string('The @field_name date is invalid', ['@field_name' => $field_label]), format_string('Invalid minute value %time has been caught.', ['%time' => $time_value])); $date_value = '2012-12-01'; $time_value = '12:15:99'; @@ -795,7 +796,7 @@ public function testInvalidField() { "{$field_name}[0][value][time]" => $time_value, ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('date is invalid', format_string('Invalid second value %time has been caught.', ['%time' => $time_value])); + $this->assertText(format_string('The @field_name date is invalid', ['@field_name' => $field_label]), format_string('Invalid second value %time has been caught.', ['%time' => $time_value])); } /**