Date fields fail to prepopulate

Created on 21 December 2023, 6 months ago
Updated 24 January 2024, 5 months ago

Problem/Motivation

Whenever I try to populate the date field, violation occur and it fails with the below log. Tested with both types of the core date module for different entities.

Invalid value for node:field_date.0: The datetime value must be a string.

If I try to typecast the $value to string before entity's set, like below, it fails with the below log.

Invalid value for user:field_birth_day.0: The datetime value '1702339200' is invalid for the format 'Y-m-d'

Then, variations of the below work:

          $entity->set($fieldName, date(\Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface::DATE_STORAGE_FORMAT, $value));

Some research shows:
https://www.drupal.org/project/drupal/issues/2875131 πŸ“Œ Datetime element formats are confusing Active

Steps to reproduce

Go vanilla.

Proposed resolution

I can't say for sure if this is a core issue or this module should add a second check for date fields or there is a conflict with the locale format setting. Any help appreciated.

πŸ’¬ Support request
Status

Needs review

Version

1.6

Component

Code

Created by

πŸ‡ΉπŸ‡·Turkey durum

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @durum
  • Status changed to Needs review 6 months ago
  • πŸ‡ΉπŸ‡·Turkey durum

    A very unhandsome workaround would be as attached. Please review or suggest. Thank you.

  • πŸ‡ΉπŸ‡·Turkey durum

    The patch from the former comment somehow stopped working. So, this gets even dirtier.

  • πŸ‡ΊπŸ‡ΈUnited States michellezeedru

    I tried the patch in #3, which would populate date fields. But all other EPP fields/parameters stopped working. Removing the patch, the other EPP fields started populating correctly again.

    I also had an odd issue with timezone, which may be unrelated to the patch. The time in the URL populated a time in my field that was 16 hours behind, which wasn't UTC or anything standard - appears to match up with China Standard Time. I.e. to get a PST time of 1/1/2024 08:30am to populate in the field, I had to enter a URL parameter of 2024-01-02T00:30.

  • πŸ‡ΉπŸ‡·Turkey durum

    It is very likely that the patch would make stop working your specific configuration, as it is only checking for format for a specific configuration. To get your project working, your projects configuration should be considered and a specific if check should be made.

    A good solution would be putting some effort to make it Drupal-way so that the type check is generic.

Production build 0.69.0 2024