summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgit2018-04-01 05:30:50 (GMT)
committerMateu Aguiló Bosch2018-04-01 05:30:50 (GMT)
commit5d80d634d3522380f153f51d984a42522ed11b97 (patch)
treed7679e473f24f578c1b5c71d81f03ade707ce90e
parente24676b765d2d2f3bda4ebda1cc99bd555dd5d7d (diff)
Issue #2953227 by vtcore: Date Time enhancer does not work with Date range fields
-rw-r--r--src/Plugin/jsonapi/FieldEnhancer/DateTimeFromStringEnhancer.php28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/Plugin/jsonapi/FieldEnhancer/DateTimeFromStringEnhancer.php b/src/Plugin/jsonapi/FieldEnhancer/DateTimeFromStringEnhancer.php
index 2378f79..b5105ff 100644
--- a/src/Plugin/jsonapi/FieldEnhancer/DateTimeFromStringEnhancer.php
+++ b/src/Plugin/jsonapi/FieldEnhancer/DateTimeFromStringEnhancer.php
@@ -19,6 +19,20 @@ class DateTimeFromStringEnhancer extends DateTimeEnhancerBase {
* {@inheritdoc}
*/
public function postProcess($value) {
+ if (is_array($value)) {
+ return array_map([$this, 'processSingleValue'], $value);
+ }
+
+ return $this->processSingleValue($value);
+ }
+
+ /**
+ * Process a single value
+ *
+ * @param $value
+ * @return string
+ */
+ protected function processSingleValue($value) {
$storage_timezone = new \DateTimezone(DATETIME_STORAGE_TIMEZONE);
$date = new \DateTime($value, $storage_timezone);
@@ -34,6 +48,20 @@ class DateTimeFromStringEnhancer extends DateTimeEnhancerBase {
* {@inheritdoc}
*/
public function prepareForInput($value) {
+ if (is_array($value)) {
+ return array_map([$this, 'prepareSingleValue'], $value);
+ }
+
+ return $this->prepareSingleValue($value);
+ }
+
+ /**
+ * Prepare a single value for input.
+ *
+ * @param $value
+ * @return string
+ */
+ protected function prepareSingleValue($value) {
$date = new \DateTime($value);
// Adjust the date for storage.