Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
CiviCRM Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Development
CiviCRM Core
Commits
eb969099
Commit
eb969099
authored
6 years ago
by
ayduns
Browse files
Options
Downloads
Patches
Plain Diff
Allow subclasses to override the determination of active tokens.
This enables variable named tokens.
parent
3a327615
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Civi/Token/AbstractTokenSubscriber.php
+18
-5
18 additions, 5 deletions
Civi/Token/AbstractTokenSubscriber.php
with
18 additions
and
5 deletions
Civi/Token/AbstractTokenSubscriber.php
+
18
−
5
View file @
eb969099
...
...
@@ -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
;
}
$
messag
eTokens
=
$
e
->
getTokenProcessor
()
->
getMessag
eTokens
();
if
(
!
isset
(
$messageTokens
[
$this
->
entity
])
)
{
$
activ
eTokens
=
$
this
->
getActiv
eTokens
(
$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.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment