X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FCore%2FEntityTokens.php;h=8f7866971b5a5230c43acc062d5b08bea1896aa5;hb=96d9c94a6d9c49a84cd38ab3b3d68167b3274d47;hp=563cc10a4965b48ac3bd61b665feee12782e4231;hpb=9abd9c0a5b2fbc47a4591b9d6ce3498f74529021;p=civicrm-core.git diff --git a/CRM/Core/EntityTokens.php b/CRM/Core/EntityTokens.php index 563cc10a49..8f7866971b 100644 --- a/CRM/Core/EntityTokens.php +++ b/CRM/Core/EntityTokens.php @@ -120,6 +120,9 @@ class CRM_Core_EntityTokens extends AbstractTokenSubscriber { } if ($this->isMoneyField($field)) { $currency = $this->getCurrency($row); + if (empty($fieldValue) && !is_numeric($fieldValue)) { + $fieldValue = 0; + } if (!$currency) { // too hard basket for now - just do what we always did. return $row->format('text/plain')->tokens($entity, $field, @@ -496,6 +499,8 @@ class CRM_Core_EntityTokens extends AbstractTokenSubscriber { * @param int $id * * @return string + * + * @throws \CRM_Core_Exception */ protected function getCustomFieldName(int $id): string { foreach ($this->getTokenMetadata() as $key => $field) { @@ -503,6 +508,9 @@ class CRM_Core_EntityTokens extends AbstractTokenSubscriber { return $key; } } + throw new CRM_Core_Exception( + "A custom field with the ID {$id} does not exist" + ); } /** @@ -515,9 +523,14 @@ class CRM_Core_EntityTokens extends AbstractTokenSubscriber { */ protected function getCustomFieldValue($entityID, string $field) { $id = str_replace('custom_', '', $field); - $value = $this->prefetch[$entityID][$this->getCustomFieldName($id)] ?? ''; - if ($value !== NULL) { - return CRM_Core_BAO_CustomField::displayValue($value, $id); + try { + $value = $this->prefetch[$entityID][$this->getCustomFieldName($id)] ?? ''; + if ($value !== NULL) { + return CRM_Core_BAO_CustomField::displayValue($value, $id); + } + } + catch (CRM_Core_Exception $exception) { + return NULL; } }