diff --git a/CRM/Event/Form/Participant.php b/CRM/Event/Form/Participant.php index 86d856759608..16eb6d964fa9 100644 --- a/CRM/Event/Form/Participant.php +++ b/CRM/Event/Form/Participant.php @@ -2171,6 +2171,7 @@ protected function sendReceipts($params, array $participants, $lineItem, $additi 'isTest' => !empty($this->_defaultValues['is_test']), 'PDFFilename' => ts('confirmation') . '.pdf', 'modelProps' => [ + 'userEnteredText' => $this->getSubmittedValue('receipt_text'), 'participantID' => $this->_id, 'eventID' => $params['event_id'], 'contributionID' => $contributionID, diff --git a/CRM/Member/Form/MembershipRenewal.php b/CRM/Member/Form/MembershipRenewal.php index aa002c5f6a6c..39a437b59b59 100644 --- a/CRM/Member/Form/MembershipRenewal.php +++ b/CRM/Member/Form/MembershipRenewal.php @@ -691,6 +691,8 @@ protected function sendReceipt($membership) { } } + // This is being replaced by userEnteredText. + $this->assign('receipt_text', $this->getSubmittedValue('receipt_text')); list($this->isMailSent) = CRM_Core_BAO_MessageTemplate::sendTemplate( [ 'workflow' => 'membership_offline_receipt', @@ -701,7 +703,7 @@ protected function sendReceipt($membership) { 'PDFFilename' => ts('receipt') . '.pdf', 'isEmailPdf' => Civi::settings()->get('invoice_is_email_pdf'), 'modelProps' => [ - 'receiptText' => $this->getSubmittedValue('receipt_text'), + 'userEnteredText' => $this->getSubmittedValue('receipt_text'), 'contactID' => $this->_receiptContactId, 'contributionID' => $this->getContributionID(), 'membershipID' => $this->getMembershipID(), diff --git a/CRM/Member/WorkflowMessage/MembershipOfflineReceipt.php b/CRM/Member/WorkflowMessage/MembershipOfflineReceipt.php index 9522240d5c46..93648fa32691 100644 --- a/CRM/Member/WorkflowMessage/MembershipOfflineReceipt.php +++ b/CRM/Member/WorkflowMessage/MembershipOfflineReceipt.php @@ -25,13 +25,4 @@ class CRM_Member_WorkflowMessage_MembershipOfflineReceipt extends GenericWorkflo use CRM_Contribute_WorkflowMessage_ContributionTrait; public const WORKFLOW = 'membership_offline_receipt'; - /** - * Additional text to include in the receipt. - * - * @var string - * - * @scope tplParams as receipt_text - */ - protected $receiptText; - } diff --git a/Civi/WorkflowMessage/GenericWorkflowMessage.php b/Civi/WorkflowMessage/GenericWorkflowMessage.php index b2e7148e1959..f01b2b9f5c15 100644 --- a/Civi/WorkflowMessage/GenericWorkflowMessage.php +++ b/Civi/WorkflowMessage/GenericWorkflowMessage.php @@ -26,6 +26,8 @@ * @method int|null getContactID() * @method $this setContact(array|null $contact) * @method array|null getContact() + * @method $this setUserEnteredText(string $text) + * @method $this setUserEnteredHTML(string $html) * * @support template-only * GenericWorkflowMessage should aim for "full" support, but it's prudent to keep @@ -117,4 +119,30 @@ protected function exportExtraTokenContext(array &$export): void { $export['smartyTokenAlias']['taxTerm'] = 'domain.tax_term'; } + /** + * Additional text to include in the receipt. + * + * @var string + * + * @scope tplParams as user_text_plain + */ + protected $userEnteredText; + + /** + * Additional html to include in the receipt. + * + * @var string + * + * @scope tplParams as user_text + */ + protected $userEnteredHTML; + + public function getUserEnteredText(): ?string { + return $this->userEnteredText ?: ($this->userEnteredHTML ? \CRM_Utils_String::htmlToText($this->userEnteredHTML) : NULL); + } + + public function getUserEnteredHTML(): ?string { + return \CRM_Utils_String::purifyHTML($this->userEnteredHTML ?: ($this->userEnteredText ? nl2br($this->userEnteredText) : '')); + } + } diff --git a/api/v3/Contribution.php b/api/v3/Contribution.php index 8f95f781fe9b..58f677b471ca 100644 --- a/api/v3/Contribution.php +++ b/api/v3/Contribution.php @@ -398,11 +398,18 @@ function civicrm_api3_contribution_sendconfirmation($params) { 'receipt_update', 'cc_receipt', 'bcc_receipt', - 'receipt_text', + 'userEnteredText', 'pay_later_receipt', 'payment_processor_id', + 'model', ]; $input = array_intersect_key($params, array_flip($allowedParams)); + if (!isset($input['model'])) { + $input['model'] = [ + // Pass through legacy receipt_text. + 'userEnteredText' => $input['tplParams']['receipt_text'] ?? NULL, + ]; + } CRM_Contribute_BAO_Contribution::sendMail($input, [], $params['id']); return []; } diff --git a/api/v3/MessageTemplate.php b/api/v3/MessageTemplate.php index 08c281f295a6..d2683efbc13a 100644 --- a/api/v3/MessageTemplate.php +++ b/api/v3/MessageTemplate.php @@ -107,6 +107,12 @@ function civicrm_api3_message_template_send($params) { unset($params[$field]); } } + if (!isset($params['model'])) { + $params['model'] = [ + // Pass through legacy receipt_text. + 'userEnteredText' => $params['tplParams']['receipt_text'] ?? NULL, + ]; + } if (empty($params['messageTemplateID'])) { if (empty($params['workflow'])) { // Can't use civicrm_api3_verify_mandatory for this because it would give the wrong field names diff --git a/tests/phpunit/CRM/Member/Form/MembershipRenewalTest.php b/tests/phpunit/CRM/Member/Form/MembershipRenewalTest.php index 198266bc1829..c2903a7ca557 100644 --- a/tests/phpunit/CRM/Member/Form/MembershipRenewalTest.php +++ b/tests/phpunit/CRM/Member/Form/MembershipRenewalTest.php @@ -298,7 +298,7 @@ public function testSubmitRecur(): void { $form->_mode = 'test'; $form->_contactID = $this->_individualId; - $form->testSubmit(); + $form->postProcess(); $membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]); $contributionRecur = $this->callAPISuccessGetSingle('ContributionRecur', ['contact_id' => $this->_individualId]); $this->assertEquals(1, $contributionRecur['is_email_receipt']); @@ -631,6 +631,7 @@ protected function getForm($formValues = [], $mode = 'test'): CRM_Member_Form_Me $form->_mode = $mode; $form->setEntityId($this->_membershipID); $form->preProcess(); + $form->buildForm(); return $form; } diff --git a/xml/templates/message_templates/event_offline_receipt_html.tpl b/xml/templates/message_templates/event_offline_receipt_html.tpl index 2226410129cd..72730472dde7 100644 --- a/xml/templates/message_templates/event_offline_receipt_html.tpl +++ b/xml/templates/message_templates/event_offline_receipt_html.tpl @@ -25,8 +25,8 @@ {assign var="greeting" value="{contact.email_greeting_display}"}{if $greeting}

{$greeting},

{/if} - {if !empty($event.confirm_email_text) AND (empty($isOnWaitlist) AND empty($isRequireApproval))} -

{$event.confirm_email_text}

+ {if $userEnteredHTML} +

{$userEnteredHTML}

{/if} {if !empty($isOnWaitlist)} diff --git a/xml/templates/message_templates/event_offline_receipt_text.tpl b/xml/templates/message_templates/event_offline_receipt_text.tpl index 62bb7854468e..b3fe71a623d4 100644 --- a/xml/templates/message_templates/event_offline_receipt_text.tpl +++ b/xml/templates/message_templates/event_offline_receipt_text.tpl @@ -1,7 +1,6 @@ {assign var="greeting" value="{contact.email_greeting_display}"}{if $greeting}{$greeting},{/if} -{if !empty($event.confirm_email_text) AND (empty($isOnWaitlist) AND empty($isRequireApproval))} -{$event.confirm_email_text} -{/if} + +{$userEnteredText} {if !empty($isOnWaitlist)} ===============================================================================