From bd272a4ca81699ed50328a8493f52caaa987decf Mon Sep 17 00:00:00 2001 From: catch <catch@35733.no-reply.drupal.org> Date: Fri, 6 Aug 2021 09:28:08 +0100 Subject: [PATCH] Issue #2508866 by paulocs, slashrsm, raman.b, vakulrai, justanothermark, kishor_kolekar, KapilV, ranjith_kumar_k_u, Rinku Jacob 13, AndrewTur, quietone, pameeela, alexpott, catch: Field description is not displayed with Timestamp datetime widget --- .../Plugin/Field/FieldWidget/TimestampDatetimeWidget.php | 6 +++++- .../tests/Drupal/FunctionalTests/Datetime/TimestampTest.php | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) 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 1ffa0109164a..0ebe7b52d5c9 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 ad42f7be93cb..c84e0c875d28 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); -- GitLab