Skip to content

Commit

Permalink
Standardise listTokens in email & pdf
Browse files Browse the repository at this point in the history
This simplifies the code to 'listtokens' across most of the pdf & email classes.

The case tokens are a bit of a hold out as ideally we would have
one function on CRM_Case_Form_Task which email & pdf would use
but we are still getting to that point - see
#21688
  • Loading branch information
eileenmcnaughton committed Oct 2, 2021
1 parent ed72890 commit fdec580
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 37 deletions.
9 changes: 9 additions & 0 deletions CRM/Activity/Form/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}

}
9 changes: 0 additions & 9 deletions CRM/Activity/Form/Task/PDF.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
9 changes: 9 additions & 0 deletions CRM/Contribute/Form/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}

}
11 changes: 0 additions & 11 deletions CRM/Contribute/Form/Task/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
9 changes: 3 additions & 6 deletions CRM/Contribute/Form/Task/PDFLetter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}

/**
Expand Down
21 changes: 21 additions & 0 deletions CRM/Core/Form/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
+--------------------------------------------------------------------+
*/

use Civi\Token\TokenProcessor;

/**
* @package CRM
* @copyright CiviCRM LLC https://civicrm.org/licensing
Expand Down Expand Up @@ -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'];
}

}
9 changes: 9 additions & 0 deletions CRM/Member/Form/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}

}
11 changes: 0 additions & 11 deletions CRM/Member/Form/Task/PDFLetter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}

0 comments on commit fdec580

Please sign in to comment.