function heartbeat_tokens in Heartbeat 7
Implements hook_tokens().
File
- modules/
heartbeat_rules/ heartbeat_rules.module, line 65 - Rules integration. Event/trigger as well as the heartbeat actions.
Code
function heartbeat_tokens($type, $tokens, array $data = array(), array $options = array()) {
$url_options = array(
'absolute' => FALSE,
);
$url_options['alias'] = TRUE;
if (isset($options['language'])) {
$url_options['language'] = $options['language'];
$language_code = $options['language']->language;
}
else {
$language_code = NULL;
}
$sanitize = !empty($options['sanitize']);
$replacements = array();
// Node activity tokens.
if ($type == 'node' && !empty($data['node'])) {
$node = $data['node'];
foreach ($tokens as $name => $original) {
switch ($name) {
case 'link':
$replacements[$original] = l($node->title, 'node/' . $node->nid, $url_options);
break;
}
}
}
// User tokens.
if ($type == 'user' && !empty($data['user'])) {
$account = $data['user'];
foreach ($tokens as $name => $original) {
switch ($name) {
case 'link':
$url_options['attributes']['class'] = array(
'user-link',
);
$name = !empty($account->realname) ? $account->realname : $account->name;
$replacements[$original] = l(format_username($account), 'user/' . $account->uid, $url_options);
break;
}
}
}
// Heartbeat activity tokens.
if ($type == 'heartbeat_activity' && !empty($data['heartbeat_activity'])) {
$heartbeat_activity = $data['heartbeat_activity'];
foreach ($tokens as $name => $original) {
switch ($name) {
case 'actor-link':
$url_options['attributes']['class'] = array(
'user-link',
);
$name = !empty($heartbeat_activity->actor->realname) ? $heartbeat_activity->actor->realname : $heartbeat_activity->actor->name;
$replacements[$original] = l(format_username($heartbeat_activity->actor), 'user/' . $heartbeat_activity->actor->uid, $url_options);
break;
}
}
}
return $replacements;
}