Skip to content
Snippets Groups Projects
Unverified Commit 67dcf790 authored by totten's avatar totten Committed by GitHub
Browse files

Merge pull request #25547 from eileenmcnaughton/559

#4080 Fix wrong pdf format selection for invoice, when configured
parents 490bdff6 eb830fb9
Branches
Tags
No related merge requests found
......@@ -233,10 +233,9 @@ class CRM_Contribute_Form_Task_Invoice extends CRM_Contribute_Form_Task {
$refundedStatusId = CRM_Utils_Array::key('Refunded', $contributionStatusID);
$cancelledStatusId = CRM_Utils_Array::key('Cancelled', $contributionStatusID);
$pendingStatusId = CRM_Utils_Array::key('Pending', $contributionStatusID);
$pdfFormat = CRM_Core_BAO_PdfFormat::getByName('default_invoice_pdf_format');
$pdfFormat = CRM_Core_BAO_MessageTemplate::getPDFFormatForTemplate('contribution_invoice_receipt');
foreach ($elementDetails as $contributionID => $detail) {
$input = $ids = [];
$input = [];
if (in_array($detail['contact'], $excludedContactIDs)) {
continue;
}
......
......@@ -203,7 +203,7 @@ class CRM_Core_BAO_MessageTemplate extends CRM_Core_DAO_MessageTemplate implemen
*/
public static function getMessageTemplates($all = TRUE, $isSMS = FALSE) {
$messageTemplates = \Civi\Api4\MessageTemplate::get()
$messageTemplates = MessageTemplate::get()
->addSelect('id', 'msg_title')
->addWhere('is_active', '=', TRUE)
->addWhere('is_sms', '=', $isSMS);
......@@ -218,6 +218,24 @@ class CRM_Core_BAO_MessageTemplate extends CRM_Core_DAO_MessageTemplate implemen
return $msgTpls;
}
/**
* Get the appropriate pdf format for the given template.
*
* @param string $workflow
*
* @return array
* @throws \CRM_Core_Exception
*/
public static function getPDFFormatForTemplate(string $workflow): array {
$pdfFormatID = MessageTemplate::get(FALSE)
->addWhere('workflow_name', '=', $workflow)
->addSelect('pdf_format_id')
->execute()->first()['pdf_format_id'] ?? 0;
// Get by ID will fall back to retrieving the default values if
// it does not find the appropriate ones - hence passing in 0 works.
return CRM_Core_BAO_PdfFormat::getById($pdfFormatID);
}
/**
* Revert a message template to its default subject+text+HTML state.
*
......
......@@ -230,6 +230,7 @@ class CRM_Core_BAO_PdfFormat extends CRM_Core_DAO_OptionValue {
* (reference) associative array of name/value pairs
*/
public static function &getByName($name) {
CRM_Core_Error::deprecatedFunctionWarning('none');
return self::getPdfFormat('name', $name);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment