function profanity_token_info in Profanity 7
Implements hook_token_info().
File
- ./
profanity.module, line 135 - Main {profanity} file.
Code
function profanity_token_info() {
$info = array();
// Build up an array of lists so we can provide helpful description text.
$wordlists = profanity_get_lists_flat();
if (!empty($wordlists)) {
$lists = array();
foreach ($wordlists as $name => $label) {
$lists[] = check_plain("{$label} ({$name})");
}
$lists_replacement = t('Possible lists: !lists', array(
'!lists' => implode(', ', $lists),
));
}
else {
$lists_replacement = t("There aren't any word lists defined, you'll need to add at least one first before using this token.");
}
// Add in tokens for all entities which have a label.
foreach (entity_get_info() as $entity_type => $entity_info) {
if (empty($entity_info['entity keys']['label'])) {
continue;
}
// Taxonomy tokens use different type text, not the entity type name.
if ($entity_type === 'taxonomy_vocabulary') {
$entity_type = 'vocabulary';
}
elseif ($entity_type === 'taxonomy_term') {
$entity_type = 'term';
}
$title_property = $entity_info['entity keys']['label'];
$info['tokens'][$entity_type][$title_property . '-profanity'] = array(
'name' => t('@label - profanity filtered', array(
'@label' => ucfirst($title_property),
)),
'description' => t('The @label for this entity processed by a specified profanity word list. Use with the word list machine name. !replacements', array(
'@label' => $title_property,
'!replacements' => $lists_replacement,
)),
'dynamic' => TRUE,
);
}
// Add in current page token.
$info['tokens']['current-page']['title-profanity'] = array(
'name' => t('Title'),
'description' => t('The title of the current page profanity filtered. Use with the word list machine name. !replacements', array(
'!replacements' => $lists_replacement,
)),
'dynamic' => TRUE,
);
return $info;
}