Where the error appears: JSONAPI output
How to reproduce: Take any entity output and change a timestamp property (changed, created) to use the "Date Time (Date Time field)" enhancer.
Result: Cannot access that entity via JSONAPI due to the above error.
Also, after going back to the regular site, this notice is thrown once:
Notice: Use of undefined constant DATETIME_STORAGE_TIMEZONE - assumed 'DATETIME_STORAGE_TIMEZONE' in Drupal\jsonapi_extras\Plugin\jsonapi\FieldEnhancer\DateTimeFromStringEnhancer->Drupal\jsonapi_extras\Plugin\jsonapi\FieldEnhancer\{closure}() (line 26 of modules/contrib/jsonapi_extras/src/Plugin/jsonapi/FieldEnhancer/DateTimeFromStringEnhancer.php).
Screenshot attached shows the field enhancer configuration.
Running PHP 7.0.33.
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | json.png | 60.69 KB | cindytwilliams |
| #6 | overwrites-save.png | 52.59 KB | cindytwilliams |
| #6 | datetime-enhancer.png | 20.56 KB | cindytwilliams |
| #5 | 3039337-jsonapi_extras-bad_timezone-5.patch | 1.54 KB | sean_e_dietrich |
Comments
Comment #2
yoruvo commentedThe problem lies with having the Date Time core module disabled (it's optional). This means that the constant used in that file is never defined.
Also, that constant is deprecated anyway; Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface::STORAGE_TIMEZONE should be used.
It begs the question how to handle this, as ideally the field enhancer should not be available with the datetime module disabled.
Comment #3
sergiu stici commentedI provided a patch. Please review.
Comment #4
sean_e_dietrichThe provided patch does not work if DateTime is not installed. Taking it back to @ivi.arocom I believe that this is a good idea to make it so there is a dependency annotation. That would include an array of modules that must be installed before these can be used.
Once applying patch get the following error
Comment #5
sean_e_dietrichPrevious patch didn't work for me. Uploading new patch.
This is also contingent that the DateTime module is enabled.
https://www.drupal.org/project/jsonapi_extras/issues/3047728
Marking Needs Review.
Comment #6
cindytwilliams commentedI tested this patch (#5), and it works as described.
With the datetime module enabled, I changed a timestamp property to use the "Date Time (Date Time field)" enhancer. It saved successfully with no errors.
Comment #7
e0ipsoFixed! Thanks for contributing.