'{event.contact_phone}' => ts('Event Contact Phone'),
'{event.description}' => ts('Event Description'),
'{event.location}' => ts('Event Location'),
- '{event.fee_amount}' => ts('Event Fees'),
+ '{event.fee_amount}' => ts('Event Fee'),
'{event.info_url}' => ts('Event Info URL'),
'{event.registration_url}' => ts('Event Registration URL'),
'{event.balance}' => ts('Event Balance'),
+--------------------------------------------------------------------+
*/
+use Civi\ActionSchedule\Event\MailingQueryEvent;
+
/**
* Class CRM_Event_Tokens
*
* implementation which is not tied to scheduled reminders, although
* that is outside the current scope.
*/
-class CRM_Event_Tokens extends \Civi\Token\AbstractTokenSubscriber {
+class CRM_Event_Tokens extends CRM_Core_EntityTokens {
/**
- * Class constructor.
+ * Get the entity name for api v4 calls.
+ *
+ * @return string
+ */
+ protected function getApiEntityName(): string {
+ return 'Event';
+ }
+
+ /**
+ * Get all tokens.
+ *
+ * This function will be removed once the parent class can determine it.
*/
- public function __construct() {
- parent::__construct('event', array_merge(
+ public function getAllTokens(): array {
+ return array_merge(
[
'event_type' => ts('Event Type'),
'title' => ts('Event Title'),
'info_url' => ts('Event Info URL'),
'registration_url' => ts('Event Registration URL'),
'fee_amount' => ts('Event Fee'),
- 'contact_email' => ts('Event Contact (Email)'),
- 'contact_phone' => ts('Event Contact (Phone)'),
+ 'contact_email' => ts('Event Contact Email'),
+ 'contact_phone' => ts('Event Contact Phone'),
'balance' => ts('Event Balance'),
],
CRM_Utils_Token::getCustomFieldTokens('Event')
- ));
+ );
}
/**
*/
public function checkActive(\Civi\Token\TokenProcessor $processor) {
// Extracted from scheduled-reminders code. See the class description.
- return !empty($processor->context['actionMapping'])
- && $processor->context['actionMapping']->getEntity() === 'civicrm_participant';
+ return ((!empty($processor->context['actionMapping'])
+ && $processor->context['actionMapping']->getEntity() === 'civicrm_participant'))
+ || in_array($this->getEntityIDField(), $processor->context['schema'], TRUE);
}
/**
*
* @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_participant') {
return;
}
];
}
+ /**
+ * Test that domain tokens are consistently rendered.
+ */
+ public function testEventTokenConsistency(): void {
+ $tokens = CRM_Core_SelectValues::eventTokens();
+ $this->assertEquals($this->getEventTokens(), $tokens);
+ $tokenProcessor = new TokenProcessor(\Civi::dispatcher(), [
+ 'controller' => __CLASS__,
+ 'smarty' => FALSE,
+ 'schema' => ['eventId'],
+ ]);
+ $this->assertEquals(array_merge($tokens, $this->getDomainTokens()), $tokenProcessor->listTokens());
+ }
+
+ /**
+ * Get expected event tokens.
+ *
+ * @return string[]
+ */
+ protected function getEventTokens(): array {
+ return [
+ '{event.event_id}' => 'Event ID',
+ '{event.title}' => 'Event Title',
+ '{event.start_date}' => 'Event Start Date',
+ '{event.end_date}' => 'Event End Date',
+ '{event.event_type}' => 'Event Type',
+ '{event.summary}' => 'Event Summary',
+ '{event.contact_email}' => 'Event Contact Email',
+ '{event.contact_phone}' => 'Event Contact Phone',
+ '{event.description}' => 'Event Description',
+ '{event.location}' => 'Event Location',
+ '{event.fee_amount}' => 'Event Fee',
+ '{event.info_url}' => 'Event Info URL',
+ '{event.registration_url}' => 'Event Registration URL',
+ '{event.balance}' => 'Event Balance',
+ ];
+ }
+
}