diff --git a/CRM/Activity/Form/Task.php b/CRM/Activity/Form/Task.php index 23afcfab94b2..ee6e1ebd2b8a 100644 --- a/CRM/Activity/Form/Task.php +++ b/CRM/Activity/Form/Task.php @@ -127,4 +127,13 @@ public function addDefaultButtons($title, $nextType = 'next', $backType = 'back' ]); } + /** + * Get the token processor schema required to list any tokens for this task. + * + * @return array + */ + public function getTokenSchema(): array { + return ['activityId']; + } + } diff --git a/CRM/Activity/Form/Task/PDF.php b/CRM/Activity/Form/Task/PDF.php index 760bde39eadc..8a7cd7abb0dd 100644 --- a/CRM/Activity/Form/Task/PDF.php +++ b/CRM/Activity/Form/Task/PDF.php @@ -56,15 +56,6 @@ public function postProcess() { CRM_Utils_System::civiExit(0); } - /** - * List available tokens for this form. - * - * @return array - */ - public function listTokens() { - return $this->createTokenProcessor()->listTokens(); - } - /** * Create a token processor * diff --git a/CRM/Contribute/Form/Task.php b/CRM/Contribute/Form/Task.php index b15aa0e23894..9a3b30871fe3 100644 --- a/CRM/Contribute/Form/Task.php +++ b/CRM/Contribute/Form/Task.php @@ -104,4 +104,13 @@ public function addDefaultButtons($title, $nextType = 'next', $backType = 'back' ]); } + /** + * Get the token processor schema required to list any tokens for this task. + * + * @return array + */ + public function getTokenSchema(): array { + return ['contributionId', 'contactId']; + } + } diff --git a/CRM/Contribute/Form/Task/Email.php b/CRM/Contribute/Form/Task/Email.php index db83653ea539..7fb87e4c97f7 100644 --- a/CRM/Contribute/Form/Task/Email.php +++ b/CRM/Contribute/Form/Task/Email.php @@ -32,15 +32,4 @@ protected function getContributionIDs(): array { return $this->getIDs(); } - /** - * List available tokens for this form. - * - * @return array - */ - public function listTokens() { - $tokens = CRM_Core_SelectValues::contactTokens(); - $tokens = array_merge(CRM_Core_SelectValues::contributionTokens(), $tokens); - return $tokens; - } - } diff --git a/CRM/Contribute/Form/Task/PDFLetter.php b/CRM/Contribute/Form/Task/PDFLetter.php index ce5839b7123a..e6b639f09e7c 100644 --- a/CRM/Contribute/Form/Task/PDFLetter.php +++ b/CRM/Contribute/Form/Task/PDFLetter.php @@ -293,15 +293,12 @@ protected function isSendEmails(): bool { } /** - * List available tokens for this form. + * Get the token processor schema required to list any tokens for this task. * * @return array */ - public function listTokens() { - $tokens = CRM_Core_SelectValues::contactTokens(); - $tokens = array_merge(CRM_Core_SelectValues::contributionTokens(), $tokens); - $tokens = array_merge(CRM_Core_SelectValues::domainTokens(), $tokens); - return $tokens; + public function getTokenSchema(): array { + return ['contributionId', 'contactId']; } /** diff --git a/CRM/Core/Form/Task.php b/CRM/Core/Form/Task.php index cb4c7349c9da..93051b63d6e1 100644 --- a/CRM/Core/Form/Task.php +++ b/CRM/Core/Form/Task.php @@ -9,6 +9,8 @@ +--------------------------------------------------------------------+ */ +use Civi\Token\TokenProcessor; + /** * @package CRM * @copyright CiviCRM LLC https://civicrm.org/licensing @@ -338,4 +340,23 @@ public function getEntityAliasField() { return $this::$entityShortname . '_id'; } + /** + * List available tokens for this form. + * + * @return array + */ + public function listTokens() { + $tokenProcessor = new TokenProcessor(Civi::dispatcher(), ['schema' => $this->getTokenSchema()]); + return $tokenProcessor->listTokens(); + } + + /** + * Get the token processor schema required to list any tokens for this task. + * + * @return array + */ + protected function getTokenSchema(): array { + return ['contactId']; + } + } diff --git a/CRM/Member/Form/Task.php b/CRM/Member/Form/Task.php index 8d5d042ab8b2..9dd37aa1b90f 100644 --- a/CRM/Member/Form/Task.php +++ b/CRM/Member/Form/Task.php @@ -95,4 +95,13 @@ public function setContactIDs() { ); } + /** + * Get the token processor schema required to list any tokens for this task. + * + * @return array + */ + public function getTokenSchema(): array { + return ['membershipId', 'contactId']; + } + } diff --git a/CRM/Member/Form/Task/PDFLetter.php b/CRM/Member/Form/Task/PDFLetter.php index 1d2354e3b4b1..d50dcffddb44 100644 --- a/CRM/Member/Form/Task/PDFLetter.php +++ b/CRM/Member/Form/Task/PDFLetter.php @@ -137,15 +137,4 @@ public function generateHTML($membershipIDs, $messageToken, $html_message): arra return $html; } - /** - * List available tokens for this form. - * - * @return array - */ - public function listTokens() { - $tokens = CRM_Core_SelectValues::contactTokens(); - $tokens = array_merge(CRM_Core_SelectValues::membershipTokens(), $tokens); - return $tokens; - } - }