Move getCustomFieldTokens to the tokens class
authorEileen McNaughton <emcnaughton@wikimedia.org>
Wed, 29 Sep 2021 04:44:32 +0000 (17:44 +1300)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Thu, 7 Oct 2021 19:37:02 +0000 (08:37 +1300)
This deprecates (quietly) another function on CRM_Utils_Token. It's a pretty small function -
the sort you'd just copy & paste if you wanted to use outside of core but
I didn't add noise. The only core place that calls this is the tokenTrait
- which is 'used' by activity tokens - but only for the handling of _N_
which I think was actually not supposed to have been included in the merge.

Anyway - I'm leaving that question for later because I'm not sure if the token
trait is used outside of core or how our final interface will look

CRM/Core/TokenTrait.php
CRM/Utils/Token.php

index bb236232decd31e12740059110b0b78f4c83c445..2f995b432669c9b4e27eb6859622f36f81c7b3a5 100644 (file)
@@ -84,7 +84,10 @@ trait CRM_Core_TokenTrait {
    */
   protected function getCustomFieldTokens(): array {
     if (!isset($this->customFieldTokens)) {
-      $this->customFieldTokens = \CRM_Utils_Token::getCustomFieldTokens(ucfirst($this->getEntityName()));
+      $this->customFieldTokens = [];
+      foreach (CRM_Core_BAO_CustomField::getFields(ucfirst($this->getEntityName())) as $id => $info) {
+        $this->customFieldTokens['custom_' . $id] = $info['label'] . ' :: ' . $info['groupTitle'];
+      }
     }
     return $this->customFieldTokens;
   }
index 58b9581ac10c30ed31999938c595382ac8df7d34..421e7cefc16ef10c7294e055473e71e6e13491c2 100644 (file)
@@ -1561,6 +1561,10 @@ class CRM_Utils_Token {
   }
 
   /**
+   * Do not use.
+   *
+   * @deprecated
+   *
    * Replace tokens for an entity.
    * @param string $entity
    * @param array $entityArray
@@ -1873,6 +1877,8 @@ class CRM_Utils_Token {
   /**
    * Get all custom field tokens of $entity
    *
+   * @deprecated
+   *
    * @param string $entity
    * @return array
    *   return custom field tokens in array('custom_N' => 'label') format