* @throws \CRM_Core_Exception
*/
protected function getRelatedTokensForEntity(string $entity, string $joinField, array $tokenList, $hiddenTokens = []): array {
+ if (!array_key_exists($entity, \Civi::service('action_object_provider')->getEntities())) {
+ return [];
+ }
$apiParams = ['checkPermissions' => FALSE];
if ($tokenList !== ['*']) {
$apiParams['where'] = [['name', 'IN', $tokenList]];
+--------------------------------------------------------------------+
*/
-use Civi\Api4\ContributionRecur;
-
/**
* Class CRM_Member_Tokens
*
*/
public function evaluateToken(\Civi\Token\TokenRow $row, $entity, $field, $prefetch = NULL) {
if ($field === 'fee') {
- $membershipType = CRM_Member_BAO_MembershipType::getMembershipType($this->getFieldValue($row, 'membership_type_id'));
- $row->tokens($entity, $field, \CRM_Utils_Money::formatLocaleNumericRoundedForDefaultCurrency($membershipType['minimum_fee'] ?? 0));
+ parent::evaluateToken($row, $entity, 'membership_type_id.minimum_fee', $prefetch);
+ $row->format('text/plain')->tokens($entity, $field, $row->tokens['membership']['membership_type_id.minimum_fee']);
}
else {
parent::evaluateToken($row, $entity, $field, $prefetch);
];
}
+ /**
+ * These tokens still work but we don't advertise them.
+ *
+ * We will actively remove from the following places
+ * - scheduled reminders
+ * - add to 'blocked' on pdf letter & email
+ *
+ * & then at some point start issuing warnings for them.
+ *
+ * @return string[]
+ */
+ protected function getDeprecatedTokens(): array {
+ return [
+ 'fee' => 'membership_type_id.minimum_fee',
+ ];
+ }
+
/**
* Get fields which need to be returned to render another token.
*
* @return array
*/
public function getDependencies(): array {
- return ['fee' => 'membership_type_id'];
+ return ['fee' => 'membership_type_id.minimum_fee'];
}
/**
'type' => 'calculated',
'options' => NULL,
'data_type' => 'integer',
- 'audience' => 'user',
+ 'audience' => 'hidden',
],
];
}
*/
protected function getRelatedTokens(): array {
$tokens = [];
- if (!in_array('ContributionRecur', array_keys(\Civi::service('action_object_provider')->getEntities()))) {
- return $tokens;
- }
$hiddenTokens = ['modified_date', 'create_date', 'trxn_id', 'invoice_id', 'is_test', 'payment_token_id', 'payment_processor_id', 'payment_instrument_id', 'cycle_day', 'installments', 'processor_id', 'next_sched_contribution_date', 'failure_count', 'failure_retry_date', 'auto_renew', 'is_email_receipt', 'contribution_status_id'];
- $contributionRecurFields = ContributionRecur::getFields(FALSE)->setLoadOptions(TRUE)->execute();
- foreach ($contributionRecurFields as $contributionRecurField) {
- $tokens['contribution_recur_id.' . $contributionRecurField['name']] = [
- 'title' => $contributionRecurField['title'],
- 'name' => 'contribution_recur_id.' . $contributionRecurField['name'],
- 'type' => 'mapped',
- 'options' => $contributionRecurField['options'] ?? NULL,
- 'data_type' => $contributionRecurField['data_type'],
- 'audience' => in_array($contributionRecurField['name'], $hiddenTokens) ? 'hidden' : 'user',
- ];
- }
+ $tokens += $this->getRelatedTokensForEntity('ContributionRecur', 'contribution_recur_id', ['*'], $hiddenTokens);
+ $tokens += $this->getRelatedTokensForEntity('MembershipType', 'membership_type_id', ['minimum_fee']);
+ $tokens += $this->getRelatedTokensForEntity('MembershipStatus', 'status_id', ['is_new']);
return $tokens;
}
/**
* Test token replacement for Print/Merge Task
+ *
+ * @throws \CRM_Core_Exception
*/
public function testMembershipTokenReplacementInPDF(): void {
$this->createLoggedInUser();
$searchFormValues = [
'radio_ts' => 'ts_sel',
- 'task' => CRM_Member_Task::PDF_LETTER,
+ 'task' => CRM_Core_Task::PDF_LETTER,
];
$membershipDates = [
'start_date' => $date,
'end_date' => date('Y-m-d', strtotime("{$date} +1 year")),
];
- $result = $this->callAPISuccess('membership', 'create', $params);
+ $result = $this->callAPISuccess('Membership', 'create', $params);
$searchFormValues['mark_x_' . $result['id']] = 1;
$params = array_merge($params,
[
], NULL, $searchFormValues);
$form->buildForm();
try {
+ $testHTML = '';
$form->postProcess();
}
catch (CRM_Core_Exception_PrematureExitException $e) {
// Assert all membership tokens are replaced correctly.
$expected = array_values($expected);
- foreach ($expected as $key => $dateVal) {
+ foreach ($expected as $dateVal) {
$this->assertStringContainsString('Anthony', $testHTML);
foreach ($tokens as $token) {
$this->assertStringContainsString($dateVal[$token], $testHTML);
/**
* Generate sample HTML for testing.
*/
- public static function getSampleHTML() {
+ public static function getSampleHTML(): array {
$tokens = [
'Test Fee' => 'fee',
'Test Type' => 'membership_type_id:label',
*
*/
public function testMembershipTokenConsistency(): void {
+ CRM_Utils_Time::setTime('2007-01-22 15:00:00');
$this->createLoggedInUser();
$this->restoreMembershipTypes();
$this->createCustomGroupWithFieldOfType(['extends' => 'Membership']);
$tokenString .= "\n{membership." . $this->getCustomFieldName('text') . '}';
// Now compare with scheduled reminder
$mut = new CiviMailUtils($this);
- CRM_Utils_Time::setTime('2007-01-22 15:00:00');
$this->callAPISuccess('ActionSchedule', 'create', [
'title' => 'job',
'subject' => 'job',
$tokens = $tokenProcessor->listTokens();
// Add in custom tokens as token processor supports these.
$expectedTokens = array_merge($expectedTokens, $this->getTokensAdvertisedByTokenProcessorButNotLegacy());
+ // Token 'fee' is deprecated & no longer advertised.
+ unset($expectedTokens['{membership.fee}']);
$this->assertEquals(array_merge($expectedTokens, $this->getDomainTokens(), $this->getRecurEntityTokens('membership')), $tokens);
$tokenProcessor->addMessage('html', $tokenString, 'text/plain');
$tokenProcessor->addRow(['membershipId' => $this->getMembershipID()]);
'{membership.start_date}' => 'Membership Start Date',
'{membership.join_date}' => 'Member Since',
'{membership.end_date}' => 'Membership Expiration Date',
+ '{membership.membership_type_id.minimum_fee}' => 'Minimum Fee',
'{membership.fee}' => 'Membership Fee',
+ '{membership.status_id.is_new}' => 'Is new membership status',
];
}
*/
protected function getExpectedMembershipTokenOutput(): string {
return '
-Expired
+New
General
1
-Expired
+New
General
January 21st, 2007
January 21st, 2007
December 21st, 2007
-100.00';
+$100.00
+$100.00
+1';
}
/**