Closed (fixed)
Project:
Time Field for Drupal 8+
Version:
2.x-dev
Component:
Code
Priority:
Critical
Category:
Bug report
Assigned:
Reporter:
Created:
27 Feb 2024 at 00:52 UTC
Updated:
13 Mar 2024 at 14:54 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #3
himanshu_jhaloya commentedComment #4
himanshu_jhaloya commentedCreated The patch Fixed the issue. Please review
Comment #6
bramdriesenYou patch is not good, it's basically partially reverting what was added in #3074674: Support empty time range values.
Furthermore, just tested this on D10.1.9 and for me this is working fine.
- Added a Time Range field to article (not required)
- Add content, only fill in title --> Save
- No issue
- Add content, fill in title, Start time 12:00, end time 00:00 --> Save
- No issue
- Add content, fill in title, Start time 00:00, end time 12:00 --> Save
- No issue
- Added a Time Range field to basic page (required)
- Add content, only fill in title --> Save --> Validation constraint (OK!)
- Add content, fill in title, Start time 12:00, end time 00:00 --> Save
- No issue
- Added content type
- Added a Time Range field to article (not required, multi value)
- Add content, only fill in title --> Save
- No issue
Did you clear the cache after updating the module? Hiding the patch as it should not be used.
Comment #7
bramdriesenComment #8
bramdriesenComment #9
joakland commentedYes, I cleared the cache. You can see the results of my test in this screenshot:
Also, when I inspect the time field, I see that the input element has a default value that is not parsable:
Comment #10
joakland commentedHaving discovered that the module is interpreting the timestamp of 86401 as empty, I was going to submit a patch, but I see there's a lot of logic built around using that timestamp to indicate an empty value. I'm curious about that decision. What's the thinking behind it? I'm going to hold off on submitting anything in the meantime.
Comment #11
bramdriesenThe reasoning behind that was explained in https://www.drupal.org/project/time_field/issues/3074674#comment-14872771 and https://www.drupal.org/project/time_field/issues/3074674#comment-14874717
What I don't understand is how that value ends up in your field as default value. Was this a node created before the upgrade? Also what version of Drupal?
Comment #12
bramdriesenAlso just noticed that the field you're referring to in screenshot #9 is not a timerange field, but a time field with seconds.
Comment #13
bramdriesenOk so that's the issue. The field validation is not working for the regular time field. The tests I wrote only cover the timerange field.
Comment #15
joakland commentedThanks for updating the empty field check logic, @BramDriesen. To answer your earlier questions (which you may not need now):
In the meantime, after reading the commits you linked to above, I'm not clear on why you're not just using an empty string for an empty field value. 86401 is actually a valid timestamp, even if it's not likely to be used.
Comment #16
bramdriesenA valid timestamp yes, but not a valid time as it will fail in this function
Time::createFromTimestamp($value);.It's been a while, but if I remember correctly, in order to allow empty values in the timerange widget, we needed a numeral value in order to do the in-range check. I remember trying to use NULL, 0 or an empty string but could not get that to fit the validation logic and actually work like it was expected in that ticket.
Comment #17
bramdriesenComment #19
bramdriesenComment #20
bramdriesenComment #21
bramdriesenComment #22
jan-e commentedIn my case (see related issue) it was also a time field. Moreover, it was intentionally hidden from some users by a hook_form_alter() statement:
$form['field_pmto_session_start_time']['widget']['#access'] = false;Despite it being hidden the value that was entered into the database was 86401. No post-processing was done on the field, so I still do not know where the 86401 originated.
Comment #23
bramdriesen86401 was the new "empty" value being returned when nothing was filled in into the field. But the single timefield was not treating that value as empty resulting in the value getting saved. And then on it turns it was throwing those errors that the time is invalid.
Not sure if we need to add an update hook to clear the database of those entries. It doesn't seem to affect anything and saving the node again removes/updates the entry.
Comment #24
jan-e commentedI could reproduce the issue on a local copy of my site.
Then I applied your MR and did not run into the error 500 anymore.
If that counts as RTBC, feel free to change the status.
With respect to an update hook to clear the values: it would be a tricky one, because you cannot change every 86401 value into 0. You have to actually delete the field instance and possibly also a revision instance.
Edit: Oops. My first test was with an incomplete patch which did not fix the issue. Hence the 'Needs work' that was still present in the form.
Comment #25
jan-e commentedComment #27
bramdriesenWill tag a release as well.
Comment #28
bramdriesenhttps://www.drupal.org/project/time_field/releases/2.1.2