Problem/Motivation
If you have a "Datetime range" -field, with "Optional end date" selected, inside a Paragraph entity you might run into a silent error in the UI when you try to add multiple paragraphs.
Steps to reproduce
- Install paragraphs module and create a new paragraph type.
- Add field of type "Datetime range" into the Paragraph and enable the "Optional end date" option provided by this module. Make sure "Date type" is set as "Date and time"
- Create a new content type and add there a field of type 'Entity reference revisions' where you target the created paragraph type. Allow unlimited number of values.
- Create a node of the type that was created in the previous step. Add a new paragraph in the created paragraph field and set the start date and time values. For the end date, only fill the date but leave the time empty.
- Attempt to add another paragraph in the same field. Nothing seems to happen and no error is given. If you check the browser console or Drupal log, you will find an error "TypeError: DateTime::createFromFormat(): Argument #2 ($datetime) must be of type string, array given"
Proposed resolution
The issue is caused by form rebuild when adding a new paragraph. In the rebuild, the end_value contains the raw form array instead of a string which is expected by the DateTime::createFromFormat -function. Let's sanitize the end_value so if it is not the expected string format, it will be NULL.
This will let rebuild go through but the missing end time will be caught in the validation when node is attempted to be saved.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | optional-end-date-check-end-value-string-3620841-2.patch | 1.12 KB | thatguy |
Comments
Comment #2
thatguy commentedComment #3
thatguy commentedComment #5
birk commentedThank you for the issue and patch.