X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FExport%2FBAO%2FExportProcessor.php;h=2a0379a917f5a42327eb389e7feb3fdb0d40a504;hb=46a36cef1aaef36857eae66093d1585e5028e635;hp=f06992ddfa4775c480edc835714f50a90270907b;hpb=3611a5326401113aca7fee86badf926c1dd75c6e;p=civicrm-core.git diff --git a/CRM/Export/BAO/ExportProcessor.php b/CRM/Export/BAO/ExportProcessor.php index f06992ddfa..2a0379a917 100644 --- a/CRM/Export/BAO/ExportProcessor.php +++ b/CRM/Export/BAO/ExportProcessor.php @@ -1612,6 +1612,43 @@ class CRM_Export_BAO_ExportProcessor { return $returnProperties; } + /** + * @param int $contactId + * @param array $exportParams + * + * @return array + */ + public function replaceMergeTokens($contactId, $exportParams) { + $greetings = []; + $contact = NULL; + + $greetingFields = [ + 'postal_greeting', + 'addressee', + ]; + foreach ($greetingFields as $greeting) { + if (!empty($exportParams[$greeting])) { + $greetingLabel = $exportParams[$greeting]; + if (empty($contact)) { + $values = [ + 'id' => $contactId, + 'version' => 3, + ]; + $contact = civicrm_api('contact', 'get', $values); + + if (!empty($contact['is_error'])) { + return $greetings; + } + $contact = $contact['values'][$contact['id']]; + } + + $tokens = ['contact' => $greetingLabel]; + $greetings[$greeting] = CRM_Utils_Token::replaceContactTokens($greetingLabel, $contact, NULL, $tokens); + } + } + return $greetings; + } + /** * The function unsets static part of the string, if token is the dynamic part. *