$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;
}
*/
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);
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.
*
* (reference) associative array of name/value pairs
*/
public static function &getByName($name) {
+ CRM_Core_Error::deprecatedFunctionWarning('none');
return self::getPdfFormat('name', $name);
}