Minor cleanup on token classes from https://github.com/civicrm/civicrm-core/pull/19584
* @copyright CiviCRM LLC https://civicrm.org/licensing
*/
+use Civi\Token\AbstractTokenSubscriber;
+use Civi\Token\Event\TokenValueEvent;
+use Civi\Token\TokenRow;
+
/**
* Class CRM_Member_Tokens
*
*
* This has been enhanced to work with PDF/letter merge
*/
-class CRM_Activity_Tokens extends \Civi\Token\AbstractTokenSubscriber {
+class CRM_Activity_Tokens extends AbstractTokenSubscriber {
use CRM_Core_TokenTrait;
/**
* @inheritDoc
*/
- public function prefetch(\Civi\Token\Event\TokenValueEvent $e) {
+ public function prefetch(TokenValueEvent $e) {
// Find all the entity IDs
$entityIds
= $e->getTokenProcessor()->getContextValues('actionSearchResult', 'entityID')
/**
* @inheritDoc
*/
- public function evaluateToken(\Civi\Token\TokenRow $row, $entity, $field, $prefetch = NULL) {
+ public function evaluateToken(TokenRow $row, $entity, $field, $prefetch = NULL) {
// maps token name to api field
$mapping = [
'activity_id' => 'id',
*
* @return array token name => token label
*/
- protected function getBasicTokens() {
+ protected function getBasicTokens(): array {
if (!isset($this->basicTokens)) {
$this->basicTokens = [
'activity_id' => ts('Activity ID'),
+--------------------------------------------------------------------+
*/
+use Civi\ActionSchedule\Event\MailingQueryEvent;
+use Civi\Token\AbstractTokenSubscriber;
+use Civi\Token\TokenProcessor;
+use Civi\Token\TokenRow;
+
/**
* Class CRM_Contribute_Tokens
*
* At time of writing, we don't have any particularly special tokens -- we just
* do some basic formatting based on the corresponding DB field.
*/
-class CRM_Contribute_Tokens extends \Civi\Token\AbstractTokenSubscriber {
+class CRM_Contribute_Tokens extends AbstractTokenSubscriber {
/**
* Get a list of tokens whose name and title match the DB fields.
* @return array
*/
- protected function getPassthruTokens() {
+ protected function getPassthruTokens(): array {
return [
'contribution_page_id',
'receive_date',
*
* @return array
*/
- protected function getAliasTokens() {
+ protected function getAliasTokens(): array {
return [
'id' => 'contribution_id',
'payment_instrument' => 'payment_instrument_id',
*
* @return bool
*/
- public function checkActive(\Civi\Token\TokenProcessor $processor) {
+ public function checkActive(TokenProcessor $processor) {
return !empty($processor->context['actionMapping'])
&& $processor->context['actionMapping']->getEntity() === 'civicrm_contribution';
}
*
* @param \Civi\ActionSchedule\Event\MailingQueryEvent $e
*/
- public function alterActionScheduleQuery(\Civi\ActionSchedule\Event\MailingQueryEvent $e) {
+ public function alterActionScheduleQuery(MailingQueryEvent $e): void {
if ($e->mapping->getEntity() !== 'civicrm_contribution') {
return;
}
/**
* @inheritDoc
*/
- public function evaluateToken(\Civi\Token\TokenRow $row, $entity, $field, $prefetch = NULL) {
+ public function evaluateToken(TokenRow $row, $entity, $field, $prefetch = NULL) {
$actionSearchResult = $row->context['actionSearchResult'];
$fieldValue = $actionSearchResult->{"contrib_$field"} ?? NULL;
<?php
+use Civi\Token\Event\TokenValueEvent;
+use Civi\Token\TokenProcessor;
+
trait CRM_Core_TokenTrait {
private $basicTokens;
/**
* @inheritDoc
*/
- public function checkActive(\Civi\Token\TokenProcessor $processor) {
+ public function checkActive(TokenProcessor $processor) {
return in_array($this->getEntityContextSchema(), $processor->context['schema']) ||
(!empty($processor->context['actionMapping'])
&& $processor->context['actionMapping']->getEntity() === $this->getEntityTableName());
/**
* @inheritDoc
*/
- public function getActiveTokens(\Civi\Token\Event\TokenValueEvent $e) {
+ public function getActiveTokens(TokenValueEvent $e) {
$messageTokens = $e->getTokenProcessor()->getMessageTokens();
if (!isset($messageTokens[$this->entity])) {
return NULL;
* Get the tokens for custom fields
* @return array token name => token label
*/
- protected function getCustomFieldTokens() {
+ protected function getCustomFieldTokens(): array {
if (!isset($this->customFieldTokens)) {
$this->customFieldTokens = \CRM_Utils_Token::getCustomFieldTokens(ucfirst($this->getEntityName()));
}