diff --git a/CRM/Export/BAO/Export.php b/CRM/Export/BAO/Export.php index 57f5ba5f0903..d27e2a36002a 100644 --- a/CRM/Export/BAO/Export.php +++ b/CRM/Export/BAO/Export.php @@ -690,43 +690,6 @@ public static function mergeSameAddress($processor, &$sqlColumns, $exportParams) } } - /** - * @param int $contactId - * @param array $exportParams - * - * @return array - */ - public static 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; - } - /** * @param \CRM_Export_BAO_ExportProcessor $processor * @param $sql @@ -753,7 +716,7 @@ public static function _buildMasterCopyArray($processor, $sql, $exportParams, $s if (!$sharedAddress) { if (!isset($contactGreetingTokens[$dao->master_contact_id])) { - $contactGreetingTokens[$dao->master_contact_id] = self::_replaceMergeTokens($dao->master_contact_id, $exportParams); + $contactGreetingTokens[$dao->master_contact_id] = $processor->replaceMergeTokens($dao->master_contact_id, $exportParams); } $masterPostalGreeting = CRM_Utils_Array::value('postal_greeting', $contactGreetingTokens[$dao->master_contact_id], $dao->master_postal_greeting @@ -763,7 +726,7 @@ public static function _buildMasterCopyArray($processor, $sql, $exportParams, $s ); if (!isset($contactGreetingTokens[$dao->copy_contact_id])) { - $contactGreetingTokens[$dao->copy_contact_id] = self::_replaceMergeTokens($dao->copy_contact_id, $exportParams); + $contactGreetingTokens[$dao->copy_contact_id] = $processor->replaceMergeTokens($dao->copy_contact_id, $exportParams); } $copyPostalGreeting = CRM_Utils_Array::value('postal_greeting', $contactGreetingTokens[$dao->copy_contact_id], $dao->copy_postal_greeting diff --git a/CRM/Export/BAO/ExportProcessor.php b/CRM/Export/BAO/ExportProcessor.php index e8dce0468f25..f407ead7ab7c 100644 --- a/CRM/Export/BAO/ExportProcessor.php +++ b/CRM/Export/BAO/ExportProcessor.php @@ -1609,6 +1609,43 @@ public function determineReturnProperties() { 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. *