function taxonomy_entity_index_token_info_alter in Taxonomy Entity Index 7
Same name and namespace in other branches
- 8 includes/taxonomy_entity_index.tokens.inc \taxonomy_entity_index_token_info_alter()
Implements hook_token_info_alter().
File
- ./
taxonomy_entity_index.tokens.inc, line 11 - Token integration for the taxonomy_entity_index module.
Code
function taxonomy_entity_index_token_info_alter(&$info) {
if (!module_exists('token')) {
// We depend on the token_get_entity_mapping() function in token.module.
return $info;
}
// Add [entity:terms] tokens for all entities.
$entities = entity_get_info();
foreach ($entities as $entity_type => $entity_info) {
if (!isset($entity_info['token type'])) {
continue;
}
// Only add to valid token types.
$token_type = $entity_info['token type'];
if (!isset($info['tokens'][$token_type]) || !isset($info['types'][$token_type])) {
continue;
}
// Do not add token if the entity type has no term fields.
$fields = taxonomy_entity_index_get_taxonomy_field_names($entity_type);
if (empty($fields)) {
continue;
}
if (!isset($info['tokens'][$token_type]['terms'])) {
$info['tokens'][$token_type]['terms'] = array(
'name' => t('Terms'),
'description' => t('The terms associated with the @entity.', array(
'@entity' => drupal_strtolower($entity_info['label']),
)),
'type' => 'array',
'module' => 'taxonomy_entity_index',
);
}
}
}