Merge pull request #9661 from monishdeb/CRM-18141
[civicrm-core.git] / Civi / Token / AbstractTokenSubscriber.php
index 81cfd91eb473a811cf916f8b5dd5f1425f17f57b..1164032de84c384de0cb3d938fef5fd2c50829f5 100644 (file)
@@ -117,6 +117,22 @@ abstract class AbstractTokenSubscriber implements EventSubscriberInterface {
     }
   }
 
+  /**
+   * Get all custom field tokens of $entity
+   *
+   * @param string $entity
+   * @return array $customTokens
+   *   return custom field tokens in array('custom_N' => 'label') format
+   */
+  public function getCustomTokens($entity) {
+    $customTokens = array();
+    foreach (\CRM_Core_BAO_CustomField::getFields($entity) as $id => $info) {
+      $customTokens["custom_$id"] = $info['label'];
+    }
+
+    return $customTokens;
+  }
+
   /**
    * Alter the query which prepopulates mailing data
    * for scheduled reminders.
@@ -148,14 +164,11 @@ abstract class AbstractTokenSubscriber implements EventSubscriberInterface {
     }
 
     $activeTokens = array_intersect($messageTokens[$this->entity], array_keys($this->tokenNames));
-    if (empty($activeTokens)) {
-      return;
-    }
 
     $prefetch = $this->prefetch($e);
 
     foreach ($e->getRows() as $row) {
-      foreach ($activeTokens as $field) {
+      foreach ((array) $activeTokens as $field) {
         $this->evaluateToken($row, $this->entity, $field, $prefetch);
       }
     }