'receipt_date',
'thankyou_date',
'tax_amount',
+ 'contribution_status_id',
];
}
];
}
+ /**
+ * Get tokens supporting the syntax we are migrating to.
+ *
+ * In general these are tokens that were not previously supported
+ * so we can add them in the preferred way or that we have
+ * undertaken some, as yet to be written, db update.
+ *
+ * See https://lab.civicrm.org/dev/core/-/issues/2650
+ *
+ * @return string[]
+ */
+ protected function getBasicTokens(): array {
+ return ['contribution_status_id' => ts('Contribution Status ID')];
+ }
+
/**
* Class constructor.
*/
$tokens['id'] = ts('Contribution ID');
$tokens['payment_instrument'] = ts('Payment Instrument');
$tokens['source'] = ts('Contribution Source');
+ // Per https://lab.civicrm.org/dev/core/-/issues/2650
+ // the intent is to deprecate this field in favour of
+ // {contribution.contribution_status_id:label}
$tokens['status'] = ts('Contribution Status');
$tokens['type'] = ts('Financial Type');
$tokens = array_merge($tokens, CRM_Utils_Token::getCustomFieldTokens('Contribution'));
return $row->format('text/plain')->tokens($entity, $field,
\CRM_Utils_Money::format($fieldValue, $actionSearchResult->contrib_currency));
}
- elseif (isset($aliasTokens[$field])) {
+ if (isset($aliasTokens[$field])) {
$row->dbToken($entity, $field, 'CRM_Contribute_BAO_Contribution', $aliasTokens[$field], $fieldValue);
}
elseif ($cfID = \CRM_Core_BAO_CustomField::getKeyID($field)) {
$row->customToken($entity, $cfID, $actionSearchResult->entity_id);
}
+ elseif (in_array($field, array_keys($this->getBasicTokens()))) {
+ // For now we just ensure that the label fields do not override the
+ // id field here.
+ // Later we will add support for contribution_status_id:label
+ $row->tokens($entity, $field, $fieldValue);
+ }
else {
$row->dbToken($entity, $field, 'CRM_Contribute_BAO_Contribution', $field, $fieldValue);
}
public function useHelloFirstNameStatus() {
$this->schedule->subject = 'Hello, {contact.first_name}. @{contribution.status}. (via subject)';
$this->schedule->body_html = '<p>Hello, {contact.first_name}. @{contribution.status}. (via body_html)</p>';
- $this->schedule->body_text = 'Hello, {contact.first_name}. @{contribution.status}. (via body_text)';
+ $this->schedule->body_text = 'Hello, {contact.first_name}. @{contribution.status} (via body_text)';
+ }
+
+ public function testTokenRendering() {
+ $this->targetDate = '20150201000107';
+ \CRM_Utils_Time::setTime('2015-02-01 00:00:00');
+ $this->addAliceDues();
+ $this->scheduleForAny();
+ $this->startOnTime();
+ $this->schedule->save();
+ $this->schedule->body_text = '
+ first name = {contact.first_name}
+ receive_date = {contribution.receive_date}
+ contribution status id = {contribution.contribution_status_id}
+ legacy style status = {contribution.status}';
+ $this->schedule->save();
+ $this->callAPISuccess('job', 'send_reminder', []);
+ $this->mut->checkMailLog([
+ 'first name = Alice',
+ 'receive_date = February 1st, 2015 12:00 AM',
+ 'contribution status id = 1',
+ 'legacy style status = Completed',
+ ]);
}
}