Problem/Motivation
In versions 1.0.0-beta5 of the field_time module, I’ve noticed that non-required time fields are automatically saving the current time as their default value. This behavior differs significantly from 1.0.0-beta3, where non-required fields would remain empty unless explicitly populated.
This change seems to have been introduced without any mention in the release notes of beta4, beta5, or subsequent releases. The lack of documentation or an explicit setting to control this behavior has made it difficult to manage time fields in use cases where blank fields are critical.
Impact
I am heavily using the field_time module to manage time intervals (e.g., durations), where an empty value is a valid and necessary state for non-required fields. Automatically saving the current time as a default introduces incorrect data and breaks the integrity of the workflows reliant on this module.
Steps to Reproduce
- Install field_time:1.0.0-beta5.
- Create a time field on any entity and do not mark it as required.
- Save the entity without filling in the time field.
- Observe that the current time is saved in the database for the field, even though it was left blank.
Expected Behavior
Non-required time fields should remain empty unless explicitly populated by the user.
Observed Behavior
Non-required time fields are automatically populated with the current time upon saving the entity.
Request
- Documentation Update: Please document this behavioral change in the release notes of 1.0.0-beta4 and later versions to inform users of the module.
- Configuration Option: Provide a setting to allow users to decide whether non-required fields should save the current time by default or remain empty.
- Bug Fix: Restore the pre-beta4 behavior where non-required fields remain empty unless explicitly populated.
Additional Context
This change has significantly impacted my use case, as I rely on non-required time fields to represent intervals or durations, and these should remain empty unless explicitly filled in by the user. Automatically saving the current time introduces incorrect data and forces unwanted manual cleanup.
I appreciate the work of the maintainers on this module and hope this feedback helps improve its usability for diverse scenarios.
| Comment | File | Size | Author |
|---|---|---|---|
| #14 | field_time-3502904-required-fields-14.patch | 2.83 KB | agentrickard |
| #11 | field_time-3502904-11-prevent-current-time-as-default.patch | 2.91 KB | jox |
Issue fork field_time-3502904
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
nidhish commentedComment #3
vladyslav svizinskyi commentedComment #4
vladyslav svizinskyi commentedComment #5
vladyslav svizinskyi commentedComment #6
vladyslav svizinskyi commentedComment #7
avpadernoComment #10
jox commentedWe're also affected by this issue. I tried both patches from #3 and #6, but unfortunately, neither of them fixes the mentioned behavior.
Comment #11
jox commentedI created a patch that fixes the main issue by making two changes:
- Leave time fields empty when they are not required, instead of setting the current time.
- Leave time range fields empty when they are not required, and avoid the error "The end time cannot be earlier or equal to the start time".
Known limitation:
There is still an open issue: if only one value of a time range is entered (e.g., only "Start time" is filled and "End time" is left empty), the entered value will be silently discarded, and both fields will be saved as empty.
I am willing to invest some more time to fix this properly (e.g., by adding a validation error if only one side of the range is filled).
Testing steps:
- Create a non-required time or time range field.
- Submit the form without entering any time: the field stays empty (✅).
- Submit the form with both "Start" and "End" filled in: the time range saves correctly (✅).
- Submit only one of "Start" or "End": currently still silently ignored (⚠️ to be fixed).
Comment #12
agentrickardIt may fail to save because both fields are registered as REQUIRED in Drupal\field_time\Plugin\Field\FieldType::propertyDefinitions()
EDIT - This does not seem to be the issue
Comment #13
agentrickardIt looks like setting NULL fails, but empty string works.
$values[$delta]['value'] = !empty($value['value']) ? (new \DateTimeImmutable($value['value']))->format('H:i:s') : '';
Comment #14
agentrickardI have updated the MR. Here is the patch version.
Comment #15
florianmuellerchI ran into the same problem, applied the patch in #14 and it worked like a charm, no config change or anything needed.
Changing this to RTBC, feel free to change it back if something is missing in the code or docs or so (didn't code-review).
Comment #16
avpadernoComment #18
strykaizerAdded support in MR for widget when seconds are disabled
Comment #19
davidwhthomas commentedThanks for this update. However, I found when using the time range widget, if the end time is left blank, then both the start and end times get saved as blank.
edit: it might be unrelated but happens because of the field TimeRangeType isEmpty check, returning empty if just one of the field property values is empty.