X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=Civi%2FToken%2FTokenRow.php;h=4f186d3d5c1ea9ccf3d84806cc76e7b8d834554c;hb=bc17b73e442ebbec13b08acb7093f03a66495b96;hp=a18a81c43533f2cead6445beee58411c44a65ee8;hpb=fa92dbe9acd43bfa2b163878eb4e4a770751263b;p=civicrm-core.git diff --git a/Civi/Token/TokenRow.php b/Civi/Token/TokenRow.php index a18a81c435..4f186d3d5c 100644 --- a/Civi/Token/TokenRow.php +++ b/Civi/Token/TokenRow.php @@ -126,6 +126,29 @@ class TokenRow { return $this; } + /** + * Update the value of a custom field token. + * + * @param string $entity + * @param int $customFieldID + * @param int $entityID + * @return TokenRow + */ + public function customToken($entity, $customFieldID, $entityID) { + $customFieldName = "custom_" . $customFieldID; + $fieldValue = civicrm_api3($entity, 'getvalue', array( + 'return' => $customFieldName, + 'id' => $entityID, + )); + + // format the raw custom field value into proper display value + if ($fieldValue) { + $fieldValue = \CRM_Core_BAO_CustomField::displayValue($fieldValue, $customFieldID); + } + + return $this->tokens($entity, $customFieldName, $fieldValue); + } + /** * Update the value of a token. Apply formatting based on DB schema. * @@ -134,6 +157,8 @@ class TokenRow { * @param string $baoName * @param array $baoField * @param mixed $fieldValue + * @return TokenRow + * @throws \CRM_Core_Exception */ public function dbToken($tokenEntity, $tokenField, $baoName, $baoField, $fieldValue) { if ($fieldValue === NULL || $fieldValue === '') {