+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2015 |
+ | Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
}
}
+ /**
+ * 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.
if (!$this->checkActive($e->getTokenProcessor())) {
return;
}
- // TODO: check if any tokens for $entity are actually used; short-circuit.
+
+ $messageTokens = $e->getTokenProcessor()->getMessageTokens();
+ if (!isset($messageTokens[$this->entity])) {
+ return;
+ }
+
+ $activeTokens = array_intersect($messageTokens[$this->entity], array_keys($this->tokenNames));
+
$prefetch = $this->prefetch($e);
+
foreach ($e->getRows() as $row) {
- foreach ($this->tokenNames as $field => $label) {
+ foreach ((array) $activeTokens as $field) {
$this->evaluateToken($row, $this->entity, $field, $prefetch);
}
}
* To perform a bulk lookup before rendering tokens, override this
* function and return the prefetched data.
*
+ * @param \Civi\Token\Event\TokenValueEvent $e
+ *
* @return mixed
*/
public function prefetch(TokenValueEvent $e) {