diff --git a/core/lib/Drupal/Core/Datetime/Plugin/Field/FieldWidget/TimestampDatetimeWidget.php b/core/lib/Drupal/Core/Datetime/Plugin/Field/FieldWidget/TimestampDatetimeWidget.php index 1ffa0109164a5c76e1afda03139ad2714d781f70..0ebe7b52d5c9236911e4daeaf77579d7f22037a5 100644 --- a/core/lib/Drupal/Core/Datetime/Plugin/Field/FieldWidget/TimestampDatetimeWidget.php +++ b/core/lib/Drupal/Core/Datetime/Plugin/Field/FieldWidget/TimestampDatetimeWidget.php @@ -35,7 +35,11 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen '#default_value' => $default_value, '#date_year_range' => '1902:2037', ]; - $element['value']['#description'] = $this->t('Format: %format. Leave blank to use the time of form submission.', ['%format' => Datetime::formatExample($date_format . ' ' . $time_format)]); + + $element['value']['#description'] = $element['#description'] !== '' + ? $element['#description'] + : $this->t('Format: %format. Leave blank to use the time of form submission.', + ['%format' => Datetime::formatExample($date_format . ' ' . $time_format)]); return $element; } diff --git a/core/tests/Drupal/FunctionalTests/Datetime/TimestampTest.php b/core/tests/Drupal/FunctionalTests/Datetime/TimestampTest.php index ad42f7be93cbee15dd958490d5580d0da46cfb08..c84e0c875d284349f1b64163f31d0a5198bebc4d 100644 --- a/core/tests/Drupal/FunctionalTests/Datetime/TimestampTest.php +++ b/core/tests/Drupal/FunctionalTests/Datetime/TimestampTest.php @@ -79,6 +79,7 @@ protected function setUp(): void { 'field_storage' => $this->fieldStorage, 'bundle' => 'entity_test', 'required' => TRUE, + 'description' => 'Description for timestamp field.', ]); $this->field->save(); @@ -114,6 +115,9 @@ public function testWidget() { // Display creation form. $this->drupalGet('entity_test/add'); + // Make sure the field description is properly displayed. + $this->assertSession()->pageTextContains('Description for timestamp field.'); + // Make sure the "datetime_timestamp" widget is on the page. $this->assertSession()->elementsCount('xpath', '//div[contains(@class, "field--widget-datetime-timestamp") and @id="edit-field-timestamp-wrapper"]', 1);