Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Developer Documentation
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
brienne
Developer Documentation
Commits
98b400b8
Unverified
Commit
98b400b8
authored
5 years ago
by
homotechsual
Committed by
GitHub
5 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #677 from mattwire/token_examples
Add token/tokenValues hook examples
parents
0b6451e0
174f6059
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
docs/hooks/hook_civicrm_tokenValues.md
+67
-8
67 additions, 8 deletions
docs/hooks/hook_civicrm_tokenValues.md
docs/hooks/hook_civicrm_tokens.md
+29
-16
29 additions, 16 deletions
docs/hooks/hook_civicrm_tokens.md
with
96 additions
and
24 deletions
docs/hooks/hook_civicrm_tokenValues.md
+
67
−
8
View file @
98b400b8
...
...
@@ -14,17 +14,76 @@ usage examples.
## Definition
hook_civicrm_tokenValues(&$values, $cids, $job = null, $tokens = array(), $context = null)
```
php
hook_civicrm_tokenValues
(
&
$values
,
$cids
,
$job
=
null
,
$tokens
=
[],
$context
=
null
)
```
## Parameters
-
$values - array of values, keyed by contact id
-
$cids - array of contactIDs that the system needs values for.
-
$job - the job_id
-
$tokens - tokens used in the mailing - use this to check whether a
token is being used and avoid fetching data for unneeded tokens
-
$context - the class name
-
$values - array of values, keyed by contact id
-
$cids - array of contactIDs that the system needs values for.
-
$job - the job_id
-
$tokens - tokens used in the mailing - use this to check whether a
token is being used and avoid fetching data for unneeded tokens
-
$context - the class name
## Returns
-
null
\ No newline at end of file
-
null
## Example
```
php
function
customtokens_civicrm_tokenValues
(
&
$values
,
$cids
,
$job
=
null
,
$tokens
=
[],
$context
=
null
)
{
$group
=
'team'
;
if
(
isset
(
$tokens
[
$group
]))
{
$token
=
'team_number'
;
if
(
!
customtokens_isTokenRequested
(
$tokens
,
$group
,
$token
))
{
return
;
}
foreach
(
$cids
as
$cid
)
{
// get team (employer) id
$individualResult
=
civicrm_api3
(
'Contact'
,
'getsingle'
,
[
'return'
=>
[
"current_employer_id"
],
'contact_id'
=>
$cid
,
]);
// if there is a team (employer) id, get team number for the team (employer)
if
(
!
$individualResult
[
'is_error'
]
&&
isset
(
$individualResult
[
'current_employer_id'
])
&&
strlen
(
$individualResult
[
'current_employer_id'
])){
$teamResult
=
civicrm_api3
(
'Contact'
,
'getsingle'
,
[
'return'
=>
[
"custom_70"
],
'id'
=>
$individualResult
[
'current_employer_id'
],
]);
// if there is a team number, display it as the token
if
(
!
$teamResult
[
'is_error'
]
&&
isset
(
$teamResult
[
'custom_70'
]))
{
$values
[
$cid
][
'team.team_number'
]
=
$teamResult
[
'custom_70'
];
}
}
}
}
}
/**
* "Send an Email" and "CiviMail" send different parameters to the tokenValues hook (in CiviCRM 5.x).
* This works around that.
*
* @param array $tokens
* @param string $group
* @param string $token
*
* @return bool
*/
function
customtokens_isTokenRequested
(
$tokens
,
$group
,
$token
)
{
// CiviMail sets $tokens to the format:
// [ 'group' => [ 'token_name' => 1 ] ]
// "Send an email" sets $tokens to the format:
// [ 'group' => [ 0 => 'token_name' ] ]
if
(
array_key_exists
(
$token
,
$tokens
[
$group
])
||
in_array
(
$token
,
$tokens
[
$group
]))
{
return
TRUE
;
}
return
FALSE
;
}
```
This diff is collapsed.
Click to expand it.
docs/hooks/hook_civicrm_tokens.md
+
29
−
16
View file @
98b400b8
...
...
@@ -15,25 +15,38 @@ for usage examples.
## Definition
hook_civicrm_tokens( &$tokens )
```
php
hook_civicrm_tokens
(
&
$tokens
)
```
## Parameters
-
$tokens: reference to the associative array of custom tokens that
are available to be used in mailings and other contexts. This will
be an empty array unless an implementation of hook_civicrm_tokens
adds items to it. Items should be added in this format:
$tokens['date'] = array(
'date.date_short' => ts("Today's Date: short format"),
'date.date_med' => ts("Today's Date: med format"),
'date.date_long' => ts("Today's Date: long format"),
);
$tokens['party'] = array(
'party.balloons' => ts("Number of balloons"),
);
-
$tokens: reference to the associative array of custom tokens that
are available to be used in mailings and other contexts. This will
be an empty array unless an implementation of hook_civicrm_tokens
adds items to it. Items should be added in this format:
```
php
$tokens
[
'date'
]
=
[
'date.date_short'
=>
ts
(
"Today's Date: short format"
),
'date.date_med'
=>
ts
(
"Today's Date: med format"
),
'date.date_long'
=>
ts
(
"Today's Date: long format"
),
];
$tokens
[
'party'
]
=
[
'party.balloons'
=>
ts
(
"Number of balloons"
),
];
```
## Returns
-
null
-
null
## Example
```
php
function
customtokens_civicrm_tokens
(
&
$tokens
)
{
$tokens
[
'team'
]
=
[
'team.team_number'
=>
'Team number'
,
];
}
```
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