Master only regression - fix empty token date
authorEileen McNaughton <emcnaughton@wikimedia.org>
Sat, 2 Oct 2021 07:20:42 +0000 (20:20 +1300)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Sat, 2 Oct 2021 07:24:50 +0000 (20:24 +1300)
Fixes a bug where an empty date was still getting put into a DateTime object
(defaulting to now)

CRM/Core/EntityTokens.php

index e8b5362ca63509f302f0f7ad8b90e574572ba313..b907e992f1eab2d276d6f57fa1a389926e7f96a7 100644 (file)
@@ -91,7 +91,7 @@ class CRM_Core_EntityTokens extends AbstractTokenSubscriber {
     if ($this->isDateField($field)) {
       try {
         return $row->format('text/plain')
-          ->tokens($entity, $field, new DateTime($fieldValue));
+          ->tokens($entity, $field, ($fieldValue ? new DateTime($fieldValue) : $fieldValue));
       }
       catch (Exception $e) {
         Civi::log()->info('invalid date token');