function subscriptions_token_info_alter in Subscriptions 7
Same name and namespace in other branches
- 2.0.x subscriptions.tokens.old.php \subscriptions_token_info_alter()
Implements hook_token_info_alter().
Parameters
array $data:
File
- ./
subscriptions.tokens.inc, line 467 - Token callbacks for the subscriptions module.
Code
function subscriptions_token_info_alter(array &$data) {
$massage_tokens =& drupal_static('subscriptions_mail_massage_tokens');
if (empty($massage_tokens)) {
// Do nothing if we're not on a Mail Editor page.
return;
}
//dpm($data, "BEF subscriptions_content_token_info_alter");
// Remove some types and tokens that are not applicable for
// Subscriptions notifications.
unset($data['types']['current-page']);
unset($data['types']['default-format']);
unset($data['types']['random']);
unset($data['tokens']['current-user']['ip-address']);
unset($data['site']['current-user']);
// Tune the labeling and explanations for our use.
$data['types']['current-user']['name'] = t('Recipient user');
$data['types']['current-user']['description'] = t('Tokens related to the user who receives the notification.');
$data['types']['user']['name'] = t('Sender user');
$data['types']['user']['description'] = t('Tokens related to the user who created the content.');
// Note: Adding tokens to existing types doesn't work here.
// Add our subs_list<TYPE> types.
$list_types = array();
foreach ($data['tokens'] as $group => $tokens) {
foreach ($tokens as $token) {
if (isset($token['type']) && preg_match('/subs_list<([a-z_]*)>/', $token['type'], $match)) {
$list_types[$match[1]] = $match[0];
}
}
}
foreach ($list_types as $type => $list) {
// Start out with Token module's 'array' type to ensure consistent terminology.
$data['tokens'][$list] = $data['tokens']['array'];
// Adjust what needs to be adjusted.
$data['tokens'][$list]['first']['type'] = $type;
$data['tokens'][$list]['last']['type'] = $type;
$data['tokens'][$list]['reversed']['type'] = $list;
$data['tokens'][$list]['key'] = array(
'type' => $type,
'name' => t('Value by key'),
'description' => t('The specific element of the array, indexed by the keys/IDs in %keys.', array(
'%keys' => 'keys',
)),
'dynamic' => TRUE,
);
$data['tokens'][$list]['index'] = array(
'type' => $type,
'name' => t('Value by index'),
'description' => t('The specific element of the array, indexed by zero-based numeric index.'),
'dynamic' => TRUE,
);
// Remove the 'value' member, use 'index' instead.
unset($data['tokens'][$list]['value']);
// Let's call it "array" because that term is more familiar to the user.
$variables = array(
'@type' => $data['types'][$type]['name'],
);
$data['types'][$list] = array(
'name' => t('Array of @type', $variables),
'description' => t('Tokens related to arrays of @type', $variables),
'needs-data' => $list,
);
}
//dpm($data, "AFT subscriptions_content_token_info_alter");
}