Skip to content
Snippets Groups Projects
Commit eb969099 authored by ayduns's avatar ayduns
Browse files

Allow subclasses to override the determination of active tokens.

This enables variable named tokens.
parent 3a327615
Branches
Tags
No related merge requests found
......@@ -45,6 +45,7 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
* 3. Implement the evaluateToken() method.
* 4. Optionally, override others:
* + checkActive()
* + getActiveTokens()
* + prefetch()
* + alterActionScheduleMailing()
* 5. Register the new class with the event-dispatcher.
......@@ -142,13 +143,10 @@ abstract class AbstractTokenSubscriber implements EventSubscriberInterface {
return;
}
$messageTokens = $e->getTokenProcessor()->getMessageTokens();
if (!isset($messageTokens[$this->entity])) {
$activeTokens = $this->getActiveTokens($e);
if (!$activeTokens) {
return;
}
$activeTokens = array_intersect($messageTokens[$this->entity], array_keys($this->tokenNames));
$prefetch = $this->prefetch($e);
foreach ($e->getRows() as $row) {
......@@ -158,6 +156,21 @@ abstract class AbstractTokenSubscriber implements EventSubscriberInterface {
}
}
/**
* To handle variable tokens, override this function and return the active tokens.
*
* @param \Civi\Token\Event\TokenValueEvent $e
*
* @return mixed
*/
public function getActiveTokens(TokenValueEvent $e) {
$messageTokens = $e->getTokenProcessor()->getMessageTokens();
if (!isset($messageTokens[$this->entity])) {
return FALSE;
}
return array_intersect($messageTokens[$this->entity], array_keys($this->tokenNames));
}
/**
* To perform a bulk lookup before rendering tokens, override this
* function and return the prefetched data.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment