Skip to content

Commit

Permalink
Ensure that the frontend title is used for contribution page details …
Browse files Browse the repository at this point in the history
…in receipts if avaliable

Add in strict checking and simplify code block in contribution page and fix comment style as per EIleen's comments
  • Loading branch information
seamuslee001 committed Oct 14, 2019
1 parent 61dbc8d commit f56ef33
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
7 changes: 6 additions & 1 deletion CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -5045,7 +5045,12 @@ protected function addContributionPageValuesToValuesHeavyHandedly(&$values) {
];
foreach ($valuesToCopy as $valueToCopy) {
if (isset($contributionPageValues[$valueToCopy])) {
$values[$valueToCopy] = $contributionPageValues[$valueToCopy];
if ($valueToCopy === 'title') {
$values[$valueToCopy] = CRM_Contribute_BAO_Contribution_Utils::getContributionPageTitle($this->contribution_page_id);
}
else {
$values[$valueToCopy] = $contributionPageValues[$valueToCopy];
}
}
}
return $values;
Expand Down
13 changes: 13 additions & 0 deletions CRM/Contribute/BAO/Contribution/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -652,4 +652,17 @@ public static function overrideDefaultCurrency($params) {
$config->defaultCurrency = CRM_Utils_Array::value('currency', $params, $config->defaultCurrency);
}

/**
* Get either the public title if set or the title of a contribution page for use in workflow message template.
* @param int $contribution_page_id
* @return string
*/
public static function getContributionPageTitle($contribution_page_id) {
$title = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $contribution_page_id, 'frontend_title');
if (empty($title)) {
$title = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $contribution_page_id, 'title');
}
return $title;
}

}
2 changes: 1 addition & 1 deletion CRM/Contribute/BAO/ContributionPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ public static function sendMail($contactID, $values, $isTest = FALSE, $returnMes
);
}

$title = isset($values['title']) ? $values['title'] : CRM_Contribute_PseudoConstant::contributionPage($values['contribution_page_id']);
$title = isset($values['title']) ? $values['title'] : CRM_Contribute_BAO_Contribution_Utils::getContributionPageTitle($values['contribution_page_id']);

// Set email variables explicitly to avoid leaky smarty variables.
// All of these will be assigned to the template, replacing any that might be assigned elsewhere.
Expand Down
2 changes: 2 additions & 0 deletions tests/phpunit/api/v3/ContributionPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ public function testSubmitMembershipBlockNotSeparatePaymentWithEmail() {
$this->callAPISuccess('membership_payment', 'getsingle', ['contribution_id' => $contribution['id']]);
$mut->checkMailLog([
'Membership Type: General',
'Test Frontend title',
]);
$mut->stop();
$mut->clearMessages();
Expand Down Expand Up @@ -1496,6 +1497,7 @@ public function setUpContributionPage($isRecur = FALSE) {
$this->params['is_recur'] = 1;
$this->params['recur_frequency_unit'] = 'month';
}
$this->params['frontend_title'] = 'Test Frontend title';
$contributionPageResult = $this->callAPISuccess($this->_entity, 'create', $this->params);
if (empty($this->_ids['price_set'])) {
$priceSet = $this->callAPISuccess('price_set', 'create', $this->_priceSetParams);
Expand Down

0 comments on commit f56ef33

Please sign in to comment.