Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev/core#522 CRM-19767 - Add case tokens to email activities #11291

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion CRM/Activity/BAO/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -1425,6 +1425,7 @@ public static function deprecatedGetActivitySQLClause($input) {
* The additional information of CC and BCC appended to the activity Details.
* @param array $contributionIds
* @param int $campaignId
* @param int $caseId
*
* @return array
* ( sent, activityId) if any email is sent and activityId
Expand All @@ -1443,7 +1444,8 @@ public static function sendEmail(
$contactIds = NULL,
$additionalDetails = NULL,
$contributionIds = NULL,
$campaignId = NULL
$campaignId = NULL,
$caseId = NULL
) {
// get the contact details of logged in contact, which we set as from email
if ($userID == NULL) {
Expand Down Expand Up @@ -1601,6 +1603,12 @@ public static function sendEmail(
$tokenHtml = NULL;
}

if ($caseId) {
$tokenSubject = CRM_Utils_Token::replaceCaseTokens($caseId, $tokenSubject, $subjectToken, $escapeSmarty);
$tokenText = CRM_Utils_Token::replaceCaseTokens($caseId, $tokenText, $messageToken, $escapeSmarty);
$tokenHtml = CRM_Utils_Token::replaceCaseTokens($caseId, $tokenHtml, $messageToken, $escapeSmarty);
}

if (defined('CIVICRM_MAIL_SMARTY') && CIVICRM_MAIL_SMARTY) {
// also add the contact tokens to the template
$smarty->assign_by_ref('contact', $values);
Expand Down
3 changes: 3 additions & 0 deletions CRM/Contact/Form/Task/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ public function postProcess() {
*/
public function listTokens() {
$tokens = CRM_Core_SelectValues::contactTokens();
if ($this->getVar('_caseId')) {
$tokens = array_merge($tokens, CRM_Core_SelectValues::caseTokens());
}
return $tokens;
}

Expand Down
3 changes: 2 additions & 1 deletion CRM/Contact/Form/Task/EmailCommon.php
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,8 @@ public static function submit(&$form, $formValues) {
array_keys($form->_toContactDetails),
$additionalDetails,
$contributionIds,
CRM_Utils_Array::value('campaign_id', $formValues)
CRM_Utils_Array::value('campaign_id', $formValues),
$form->getVar('_caseId')
);

$followupStatus = '';
Expand Down
18 changes: 10 additions & 8 deletions CRM/Contact/Form/Task/PDFLetterCommon.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,8 @@ public static function processMessageTemplate($formValues) {
* Process the form after the input has been submitted and validated.
*
* @param CRM_Core_Form $form
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public static function postProcess(&$form) {
$formValues = $form->controller->exportValues($form->getName());
Expand All @@ -379,9 +379,16 @@ public static function postProcess(&$form) {
}

foreach ($form->_contactIds as $item => $contactId) {
$caseId = NULL;
$params = array('contact_id' => $contactId);

$caseId = $form->getVar('_caseId');
if (empty($caseId) && !empty($form->_caseIds[$item])) {
$caseId = $form->_caseIds[$item];
}
if ($caseId) {
$params['case_id'] = $caseId;
}

list($contact) = CRM_Utils_Token::getTokenDetails($params,
$returnProperties,
$skipOnHold,
Expand All @@ -397,12 +404,7 @@ public static function postProcess(&$form) {
}

$tokenHtml = CRM_Utils_Token::replaceContactTokens($html_message, $contact[$contactId], TRUE, $messageToken);
if (!empty($form->_caseId)) {
$caseId = $form->_caseId;
}
if (empty($caseId) && !empty($form->_caseIds[$item])) {
$caseId = $form->_caseIds[$item];
}

if ($caseId) {
$tokenHtml = CRM_Utils_Token::replaceCaseTokens($caseId, $tokenHtml, $messageToken);
}
Expand Down
4 changes: 2 additions & 2 deletions CRM/Utils/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -1613,7 +1613,7 @@ public static function replaceEntityTokens($entity, $entityArray, $str, $knownTo

/**
* @param int $caseId
* @param int $str
* @param string $str
* @param array $knownTokens
* @param bool $escapeSmarty
* @return string
Expand Down Expand Up @@ -1883,7 +1883,7 @@ public static function formatTokensForDisplay($tokens) {
else {
$split = explode('.', trim($k, '{}'));
if (isset($split[1])) {
$entity = array_key_exists($split[1], CRM_Core_DAO_Address::export()) ? 'Address' : ucfirst($split[0]);
$entity = array_key_exists($split[1], CRM_Core_DAO_Address::export()) ? 'Address' : ucwords(str_replace('_', ' ', $split[0]));
}
else {
$entity = 'Contact';
Expand Down