DomainTokens - {domain.now} should abide by mocked times
[civicrm-core.git] / CRM / Core / DomainTokens.php
index 8aaafaff4ca5dc6b9fbbac597f57e19647ec08bb..fe7384270bef950898ba84e09d58867a5b837cc9 100644 (file)
@@ -47,6 +47,7 @@ class CRM_Core_DomainTokens extends AbstractTokenSubscriber {
       'email' => ts('Domain (organization) email'),
       'id' => ts('Domain ID'),
       'description' => ts('Domain Description'),
+      'now' => ts('Current time/date'),
     ];
   }
 
@@ -55,6 +56,11 @@ class CRM_Core_DomainTokens extends AbstractTokenSubscriber {
    * @throws \CRM_Core_Exception
    */
   public function evaluateToken(TokenRow $row, $entity, $field, $prefetch = NULL): void {
+    if ($field === 'now') {
+      $nowObj = (new \DateTime())->setTimestamp(\CRM_Utils_Time::time());
+      $row->format('text/html')->tokens($entity, $field, $nowObj);
+      return;
+    }
     $row->format('text/html')->tokens($entity, $field, self::getDomainTokenValues()[$field]);
     $row->format('text/plain')->tokens($entity, $field, self::getDomainTokenValues(NULL, FALSE)[$field]);
   }