Skip to content
Snippets Groups Projects
Unverified Commit 243eec2a authored by eileen's avatar eileen :8ball: Committed by GitHub
Browse files

Merge pull request #13186 from aydun/override_active_tokens

(REF) Allow subclasses of AbstractTokenSubscriber to override the determination of active tokens.
parents 762e3fc8 eb969099
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