I like using the conditional fields module to streamline relevant fields and workflows for content editors. I have an event content type where I'm using a smart date field, and I wanted to add a simple boolean field for "Schedule presentation", that would hide or disable the smart date field if unchecked, simplifying the UI, and only showing the date field if someone was ready or wanted to schedule a date.
When either of these options were enabled, however, attempting to save the content with the boolean unchecked (and therefore smart date either hidden or disabled) would result in a WSOD. The following was in the error log:
Referrer http://mysite.com/node/add/learning_topic
Message Error: Class "Drupal\datetime_range\Plugin\Field\FieldWidget\DateRangeWidgetBase" not found in Drupal\smart_date\Plugin\Field\FieldWidget\SmartDateWidgetBase->massageFormValues() (line 295 of /var/www/html/web/modules/contrib/smart_date/src/Plugin/Field/FieldWidget/SmartDateWidgetBase.php).
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | smart_date-conditional_fields-3356452-4.patch | 1.43 KB | mandclu |
| #3 | Screenshot 2023-04-27 182055.jpg | 115.41 KB | w01f |
| #3 | Screenshot 2023-04-27 182019.jpg | 62.64 KB | w01f |
| #3 | Screenshot 2023-04-27 181938.jpg | 89.88 KB | w01f |
Comments
Comment #2
mandclu commentedBased on where that error is triggered, it seems as though the field for which you're using the Smart Date widget is neither a Smart Date field, nor a core Date Range field. What kind of field is it?
Comment #3
w01f commentedIt's a "Smart date range" field. I'm including screenshots of the fields, form display, and the display using Layout Builder.
Drupal 10.0.8
Smart Date 4.0.0-rc1
Comment #4
mandclu commentedHmmm I wonder if the conditional fields module unsets the 'storage' key on the field, which is causing that clause to be triggered. Here's a patch that checks for the class that is intended to be used as a fallback, with a fallback strategy of just skipping any additional processing, which in this use case sounds like would be appropriate anyway.
Comment #5
w01f commentedPatch tested and works as expected! Tested with boolean checked and unchecked, and the dependent field filled in and left blank. All options seem to work fine now.
Comment #7
mandclu commentedThanks for the feedback. Merged in.
Comment #8
mandclu commented