Skip to content

Commit

Permalink
Add userEnteredText as generic workflow template smarty variable
Browse files Browse the repository at this point in the history
This makes userEnteredText a property across all WorkflowMessages - with it outputting
the smarty variable user_text

We already had receipt_text on the membership forms - but that is a bit too specific
- user is perhaps a bit impersonal - I did contemplate form_text :
  • Loading branch information
eileenmcnaughton committed Oct 2, 2023
1 parent c53c1b2 commit b90fd11
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 17 deletions.
1 change: 1 addition & 0 deletions CRM/Event/Form/Participant.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion CRM/Member/Form/MembershipRenewal.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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(),
Expand Down
9 changes: 0 additions & 9 deletions CRM/Member/WorkflowMessage/MembershipOfflineReceipt.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}
28 changes: 28 additions & 0 deletions Civi/WorkflowMessage/GenericWorkflowMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) : ''));
}

}
9 changes: 8 additions & 1 deletion api/v3/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [];
}
Expand Down
6 changes: 6 additions & 0 deletions api/v3/MessageTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion tests/phpunit/CRM/Member/Form/MembershipRenewalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
<td>
{assign var="greeting" value="{contact.email_greeting_display}"}{if $greeting}<p>{$greeting},</p>{/if}

{if !empty($event.confirm_email_text) AND (empty($isOnWaitlist) AND empty($isRequireApproval))}
<p>{$event.confirm_email_text}</p>
{if $userEnteredHTML}
<p>{$userEnteredHTML}</p>
{/if}

{if !empty($isOnWaitlist)}
Expand Down
Original file line number Diff line number Diff line change
@@ -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)}
===============================================================================
Expand Down

0 comments on commit b90fd11

Please sign in to comment.