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 :
'tplParams' => $tplParams,
'PDFFilename' => $pdfFileName,
'tokenContext' => ['contributionId' => $contribution->id, 'contactId' => $contribution->contact_id],
+ 'modelProps' => [
+ 'userEnteredText' => $params['email_comment'] ?? NULL,
+ ],
];
// from email address
$fileName = self::putFile($html, $pdfFileName, $pdfFormat);
self::addActivities($subject, $contribution->contact_id, $fileName, $params, $contribution->id);
}
- elseif ($component == 'event') {
+ elseif ($component === 'event') {
$email = CRM_Contact_BAO_Contact::getPrimaryEmail($contribution->contact_id);
- $sendTemplateParams['tplParams'] = array_merge($tplParams, ['email_comment' => $params['email_comment']]);
+ $sendTemplateParams['tplParams'] = $tplParams;
$sendTemplateParams['from'] = $fromEmailAddress;
$sendTemplateParams['toEmail'] = $email;
$sendTemplateParams['cc'] = $values['cc_confirm'] ?? NULL;
$params['attachments'] = [];
}
$params['attachments'][] = CRM_Utils_Mail::appendPDF($params['PDFFilename'], $params['html'], $mailContent['format']);
+ // This specifically allows the invoice code to attach an invoice & have
+ // a different message body. It will be removed & replaced with something
+ // saner so avoid trying to leverage this. There are no universe usages outside
+ // the core invoice task as of Dec 2023
if (isset($params['tplParams']['email_comment'])) {
+ if ($params['workflow'] !== 'contribution_invoice_receipt') {
+ CRM_Core_Error::deprecatedWarning('unsupported parameter email_comment used');
+ }
$params['html'] = $params['tplParams']['email_comment'];
$params['text'] = strip_tags($params['tplParams']['email_comment']);
}
'PDFFilename' => ts('confirmation') . '.pdf',
'modelProps' => [
'participantID' => $participantID,
+ 'userEnteredText' => $this->getSubmittedValue('receipt_text'),
'eventID' => $params['event_id'],
'contributionID' => $contributionID,
],
'isEmailPdf' => Civi::settings()->get('invoice_is_email_pdf'),
'isTest' => (bool) ($this->_action & CRM_Core_Action::PREVIEW),
'modelProps' => [
- 'receiptText' => $this->getSubmittedValue('receipt_text'),
+ 'userEnteredText' => $this->getSubmittedValue('receipt_text'),
'contributionID' => $formValues['contribution_id'],
'contactID' => $this->_receiptContactId,
'membershipID' => $this->getMembershipID(),
}
}
+ // This is being replaced by userEnteredText.
+ $this->assign('receipt_text', $this->getSubmittedValue('receipt_text'));
[$this->isMailSent] = CRM_Core_BAO_MessageTemplate::sendTemplate(
[
'workflow' => 'membership_offline_receipt',
'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(),
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;
-
}
* @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
$export['smartyTokenAlias']['taxTerm'] = 'domain.tax_term';
}
+ /**
+ * Additional text to include in the receipt.
+ *
+ * @var string
+ *
+ * @scope tplParams as userTextPlain
+ */
+ protected $userEnteredText;
+
+ /**
+ * Additional html to include in the receipt.
+ *
+ * @var string
+ *
+ * @scope tplParams as userText
+ */
+ 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) : ''));
+ }
+
}
'receipt_text',
'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 [];
}
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
<?php
+declare(strict_types = 1);
use Civi\Api4\Address;
use Civi\Api4\Event;
use Civi\Api4\LineItem;
'is_default' => 1,
]);
$oldMsg = $result['values'][0]['msg_html'];
- $pos = strpos($oldMsg, 'Please print this confirmation');
- $newMsg = substr_replace($oldMsg, '<p>Test event type - {event.event_type_id}</p>', $pos, 0);
+ $newMsg = substr_replace($oldMsg, '<p>Test event type - {event.event_type_id}</p>', 0, 0);
$this->callAPISuccess('MessageTemplate', 'create', [
'id' => $result['id'],
'msg_html' => $newMsg,
$event = $this->eventCreateUnpaid($eventParams);
}
$submittedValues['event_id'] = $event['id'];
+ $submittedValues['receipt_text'] = 'Contact the Development Department if you need to make any changes to your registration.';
return $this->getTestForm('CRM_Event_Form_Participant', $submittedValues, ['cid' => $submittedValues['contact_id']])->processForm(FormWrapper::BUILT);
}
$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']);
$form->_mode = $mode;
$form->setEntityId($this->_membershipID);
$form->preProcess();
+ $form->buildForm();
return $form;
}
</table>
{/if}
<table style="font-family: Arial, Verdana, sans-serif;" width="100%" height="100" border="0" cellpadding="5" cellspacing="0">
- {if $email_comment}
+ {if $userText}
<tr>
- <td><font size="1" colspan="3">{$email_comment}</font></td>
+ <td><font size="1" colspan="3">{$userText}</font></td>
</tr>
{/if}
<tr>
<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 $userText}
+ <p>{$userText}</p>
{/if}
{if !empty($isOnWaitlist)}
<tr>
<td>
{assign var="greeting" value="{contact.email_greeting_display}"}{if $greeting}<p>{$greeting},</p>{/if}
- {if $receipt_text}
- <p>{$receipt_text|htmlize}</p>
+ {if $userText}
+ <p>{$userText}</p>
{else}
<p>{ts}Thank you for this contribution.{/ts}</p>
{/if}
{assign var="greeting" value="{contact.email_greeting_display}"}{if $greeting}{$greeting},{/if}
-{if $receipt_text}
-{$receipt_text}
+{if $userTextPlain}
+{$userTextPlain}
{else}{ts}Thank you for this contribution.{/ts}{/if}
{if !$isShowLineItems}
<tr>
<td>
{assign var="greeting" value="{contact.email_greeting_display}"}{if $greeting}<p>{$greeting},</p>{/if}
- {if !empty($receipt_text)}
- <p>{$receipt_text|htmlize}</p>
+ {if $userText}
+ <p>{$userText}</p>
{/if}
{if {contribution.balance_amount|boolean} && {contribution.is_pay_later|boolean}}
<p>{contribution.pay_later_receipt}</p>