I'm trying to privide a token for mailing related automated messages. I followed the instructions about hook_civicrm_tokens
and hook_civicrm_tokenValues
but it does only work for "CiviMail" mails. In mails for group subscriptions (at least "Subscribe Message", "Resubscribe Message", "Unsubscribe Message" and "Welcome Message") the custom token will not be replaced.
function mysite_civicrm_tokens(&$tokens){
// Define tokens for date (like today's year)
$tokens['date'] = [
'date.year' => ts("Today's Date: year")
];
}
function mysite_civicrm_tokenValues(&$values, $cids, $job = null, $tokens = [], $context = null) {
// Set tokens values for date
if(isset($tokens['date'])) {
// TODO: Check if token is required.
foreach ($cids as $cid) {
$values[$cid]['date.year'] = date("Y");
}
}
}
The custom token defined in mysite_civicrm_tokens
is not availible in mysite_civicrm_tokenValues
although I have placed it inside the mailing components under civicrm/admin/component.
I know that those mails are handled different from CiviMail mails so I guess there might be another way to solve this.