From 08a58ec346be82b93a9f79a23ecf8e1277e216a9 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Thu, 21 Sep 2023 21:40:37 +1200 Subject: [PATCH] Switch all participant token listing to TokenProcessor, add deprecation --- CRM/Badge/Form/Layout.php | 24 +++++++------------ CRM/Core/SelectValues.php | 1 + .../CRM/Utils/TokenConsistencyTest.php | 9 ++----- 3 files changed, 12 insertions(+), 22 deletions(-) diff --git a/CRM/Badge/Form/Layout.php b/CRM/Badge/Form/Layout.php index 661fb70ac3..6f5b9a4189 100644 --- a/CRM/Badge/Form/Layout.php +++ b/CRM/Badge/Form/Layout.php @@ -9,6 +9,8 @@ +--------------------------------------------------------------------+ */ +use Civi\Token\TokenProcessor; + /** * * @package CRM @@ -49,21 +51,13 @@ class CRM_Badge_Form_Layout extends CRM_Admin_Form { $this->add('text', 'description', ts('Description'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_PrintLabel', 'title')); - // get the tokens - at the point of rendering the token processor is used so - // the only reason for this cut-down set of tokens is UI on this - // screen and / or historical. - $contactTokens = CRM_Core_SelectValues::contactTokens(); - $eventTokens = [ - '{event.event_id}' => ts('Event ID'), - '{event.title}' => ts('Event Title'), - // This layout selection is day + month eg October 27th - // obviously someone felt year was not logical for dates. - '{event.start_date|crmDate:"%B %E%f"}' => ts('Event Start Date'), - '{event.end_date|crmDate:"%B %E%f"}' => ts('Event End Date'), - ]; - $participantTokens = CRM_Core_SelectValues::participantTokens(); - - $tokens = array_merge($contactTokens, $eventTokens, $participantTokens); + $tokenProcessor = new TokenProcessor(Civi::dispatcher(), ['schema' => ['participantId', 'contactId', 'eventId']]); + $tokens = $tokenProcessor->listTokens(); + // This layout selection is day + month eg October 27th + // obviously someone felt year was not logical for dates. + $tokens['{event.start_date|crmDate:"%B %E%f"}'] = ts('Event Start Date - Day & Month'); + $tokens[] = ts('Event End Date - Day & Month'); + asort($tokens); $tokens = array_merge(['spacer' => ts('- spacer -')] + $tokens); diff --git a/CRM/Core/SelectValues.php b/CRM/Core/SelectValues.php index 0573b1a8a1..e63d119468 100644 --- a/CRM/Core/SelectValues.php +++ b/CRM/Core/SelectValues.php @@ -634,6 +634,7 @@ class CRM_Core_SelectValues { * @return array */ public static function participantTokens(): array { + CRM_Core_Error::deprecatedFunctionWarning('user TokenProcessor'); $tokenProcessor = new TokenProcessor(Civi::dispatcher(), ['schema' => ['participantId']]); $allTokens = $tokenProcessor->listTokens(); foreach (array_keys($allTokens) as $token) { diff --git a/tests/phpunit/CRM/Utils/TokenConsistencyTest.php b/tests/phpunit/CRM/Utils/TokenConsistencyTest.php index 8a69080a6f..65a31a3abc 100644 --- a/tests/phpunit/CRM/Utils/TokenConsistencyTest.php +++ b/tests/phpunit/CRM/Utils/TokenConsistencyTest.php @@ -752,9 +752,6 @@ December 21st, 2007 $this->createLoggedInUser(); $this->setupParticipantScheduledReminder(); - $tokens = CRM_Core_SelectValues::participantTokens(); - $this->assertEquals(array_diff_key($this->getParticipantTokens(), $this->getUnadvertisedTokens()), $tokens); - $mut = new CiviMailUtils($this); $tokenProcessor = new TokenProcessor(\Civi::dispatcher(), [ @@ -762,9 +759,7 @@ December 21st, 2007 'smarty' => FALSE, 'schema' => ['participantId'], ]); - $this->assertEquals(array_merge($tokens, $this->getEventTokens(), $this->getDomainTokens()), $tokenProcessor->listTokens()); - - $this->callAPISuccess('job', 'send_reminder', []); + $this->callAPISuccess('Job', 'send_reminder', []); $expected = $this->getExpectedParticipantTokenOutput(); $mut->checkMailLog([$expected]); @@ -1030,7 +1025,7 @@ United States', $tokenProcessor->getRow(0)->render('message')); * * @return string[] */ - protected function getRecurEntityTokens($entity): array { + protected function getRecurEntityTokens(string $entity): array { return [ '{' . $entity . '.contribution_recur_id.id}' => 'Recurring Contribution ID', '{' . $entity . '.contribution_recur_id.contact_id}' => 'Contact ID', -- 2.25.1