Problem/Motivation

When \Drupal\Core\Datetime\Plugin\Field\FieldWidget\TimestampDatetimeWidget adds timestamp format information to the field widget it overrides user-set description.

Steps to reproduce:

  1. Install Drupal
  2. Add timestamp field to basic page content type
  3. Add custom help text for the timestamp field on the field edit page
  4. Check that the field is displayed in the edit form
  5. Create new content of the type basic page
  6. The custom help text is not displayed but the default will be shown which is:" Format: 2017-09-29 11:34:58. Leave blank to use the time of form submission."

Proposed resolution

Make use field description is correctly displayed along with format info.

Comments

slashrsm’s picture

Status: Active » Needs review
StatusFileSize
new1.09 KB
primsi’s picture

Status: Needs review » Reviewed & tested by the community

Looks ok.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 1: 2508866_1.patch, failed testing.

Status: Needs work » Needs review

slashrsm queued 1: 2508866_1.patch for re-testing.

slashrsm’s picture

Status: Needs review » Reviewed & tested by the community

Still RTBC.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

Looks like a test will be useful here to prove we don't break it.

wuinfo - bill wu’s picture

What is the URL? Can't find it from field setting for article content type.

slashrsm’s picture

Status: Needs work » Needs review
StatusFileSize
new1.32 KB
new2.42 KB
new2.32 KB

Added test.

The last submitted patch, 8: 2508866_8_TEST_ONLY.patch, failed testing.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

wturrell’s picture

Status: Needs review » Needs work
Issue tags: +Needs steps to reproduce, +Needs screenshots, +Needs issue summary update

Could someone clarify steps to reproduce for this please? (a before/after screenshot would help)

For me, in 8.3.x, the label and custom help text both display correctly on the form. The dd/mm/yyyy placeholder is in the input itself.
The only widget is Datetime Timestamp and there are no widget settings.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

andrewtur’s picture

Hi,

I think what they are trying to say is that if you create a timestamp field on a entity the help text entered for this field is not shown on the edit/create form

Steps to reproduce:
1) install drupal8 default
2) add timestamp field to basic page content type
3) add custom help text for the timestamp field on the field edit page
4) check that the field is displayed in the edit form
5) create new content of the type basic page
6) the custom help text is not displayed but the default will be shown which is:" Format: 2017-09-29 11:34:58. Leave blank to use the time of form submission."

The desired result is that the help text you have entered for the field should be displayed in addition to the Format information.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

justanothermark’s picture

Status: Needs work » Needs review
StatusFileSize
new34.47 KB
new42.79 KB
new1.9 KB

#15 includes steps to reproduce and this issue still exists in 8.6. However, the patch no longer applies and we needed a patch that applies so here's a re-roll (with before/after patch applies screenshots).

Status: Needs review » Needs work

The last submitted patch, 18: 2508866-18.patch, failed testing. View results

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

pameeela’s picture

Version: 8.9.x-dev » 9.0.x-dev
Issue summary: View changes
Issue tags: -Needs steps to reproduce, -Needs screenshots, -Needs issue summary update

Updated IS and added screenshots from #15. I've also confirmed this is still an issue in 9.0.1.

pameeela’s picture

Issue tags: +Bug Smash Initiative
raman.b’s picture

Version: 9.0.x-dev » 9.2.x-dev
Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new1.08 KB
new2.17 KB
new965 bytes

Addressing the failed test case

The last submitted patch, 24: 2508866-24-test-only.patch, failed testing. View results

ranjith_kumar_k_u’s picture

StatusFileSize
new259.85 KB
new273.63 KB

The above patch works fine , It shows the entered help text.

Before patch
before patch

After patch
after patch

ranjith_kumar_k_u’s picture

Status: Needs review » Reviewed & tested by the community
paulocs’s picture

StatusFileSize
new12.89 KB
new11.93 KB

RTBC+1.
Attached images to confirm.

catch’s picture

Status: Reviewed & tested by the community » Needs work

I feel like we should be relying on the description configured (or not) by the user, and not have this default description at all to be honest - we have configurable descriptions for a reason and the current code breaks that.

vakulrai’s picture

Status: Needs work » Needs review
StatusFileSize
new4.31 KB

The description field must be configurable from the field configuration and the configured text must comes in place of "default text" on entity form.

I am adding a patch which will check if user has entered descriptions then same should appear on form else the default text should come.

Added tests.

Please review.

vakulrai’s picture

Previous patch was broken , re uploading the patch.

kapilv’s picture

StatusFileSize
new4.23 KB
quietone’s picture

Status: Needs review » Needs work
Issue tags: +Needs issue summary update

Picked this for to review this evening.

The issue summary has steps to reproduce which is really helpful, thanks pameeela. The proposed resolution is a bit difficult to understand, but I think I know what is intended. There are no remaining tasks so I am not sure what still needs to be done. This will need after screen shot in the IS as well. Tagging needs summary update.

@vakulrai and @KapilV, To help reviewers add an interdiff, or a diff, whichever is appropriate. There are instructions for creating an interdiff in the handbook. If you think a diff is not needed, just add a comment stating why. Thanks.

I applied the patch locally and tested and it does work, if I understand the IS correctly.

  1. +++ b/core/lib/Drupal/Core/Datetime/Plugin/Field/FieldWidget/TimestampDatetimeWidget.php
    @@ -35,7 +35,8 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
    +    $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)]);
    

    The length of this line makes it hard to read. Split on Three lines
    $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)]);

  2. +++ b/core/lib/Drupal/Core/Datetime/Plugin/Field/FieldWidget/TimestampDatetimeWidget.php
    index e20b15312a..081d75cf29 100644
    --- a/core/profiles/standard/tests/src/Functional/StandardTest.php
    

    I do not understand why the tests are added to StandardTest, which "* Tests Standard installation profile expectations.". There must be an existing test of the TimestampDatetimeWidget somewhere this can be added to. I don't know where that would be so I did find . -iname \*timestamp\*test.php | grep -i functional and that gave two results. And of those, this looks like the one to use, core/tests/Drupal/FunctionalTests/Datetime/TimestampTest.php. The testing should be added to this file.

quietone’s picture

I tried to edit my comment to make this fix but it just keeps telling me the form is outdated. So here is the format change for 33.1

The length of this line makes it hard to read. Split on Three lines

  $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)]);
kishor_kolekar’s picture

Status: Needs work » Needs review
StatusFileSize
new4.24 KB
new981 bytes

Hey, I have tried to cover the points mentioned in #33.1
Please review

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

rinku jacob 13’s picture

StatusFileSize
new145.42 KB
new141.82 KB

Verified and tested patch#35 on drupal 9.3.x-dev version. Adding screenshot for the reference.
getting output like this...

paulocs’s picture

Assigned: Unassigned » paulocs
Status: Needs review » Needs work

In patch #35, the tests are not placed correctly.
I'll work on it.

paulocs’s picture

Assigned: paulocs » Unassigned
Status: Needs work » Needs review
StatusFileSize
new2.32 KB
new5.06 KB
new3.38 KB

The tests are passing locally but falling with drupal test bots because I guess Datetime::formatExample($date_format . ' ' . $time_format); are generating different time in TimestampTest.php and in TimestampDatetimeWidget.php.

The last submitted patch, 39: 2508866-39-TEST-ONLY.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 39: 2508866-39.patch, failed testing. View results

paulocs’s picture

Status: Needs work » Needs review
StatusFileSize
new1.96 KB
new2.1 KB

New patch without the default description test.

kleiton_rodrigues’s picture

StatusFileSize
new52.52 KB
new48.07 KB

The patch #42 applies cleanly and works as expected.
looks good to me

BEFORE
Before patch #42

AFTER
After patch #42

rescandon’s picture

Status: Needs review » Reviewed & tested by the community

Verified and tested patch#42 on drupal 9.3.x-dev version.

The field is displaying the custom help text

  • catch committed bd272a4 on 9.3.x
    Issue #2508866 by paulocs, slashrsm, raman.b, vakulrai, justanothermark...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed bd272a4 and pushed to 9.3.x. Thanks!

catch’s picture

Removing some issue credit for duplicate screenshots. Once there's a before/after screenshot of a patch on an issue, there's no need to add a second one.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.