1.20.x entity.tokens.inc | entity_token_info_alter(&$info) |
Implements hook_token_info_alter().
File
- modules/
entity/ entity.tokens.inc, line 10 - Token callbacks for the entity module.
Code
function entity_token_info_alter(&$info) {
// Add [token:url] tokens for any URI-able entities.
$entities = entity_get_info();
foreach ($entities as $entity => $entity_info) {
if (!isset($entity_info['token type'])) {
continue;
}
$token_type = $entity_info['token type'];
if (!isset($info['types'][$token_type]) || !isset($info['tokens'][$token_type])) {
continue;
}
// Add [entity:url] tokens if they do not already exist.
if (!isset($info['tokens'][$token_type]['url']) && !empty($entity_info['uri callback'])) {
$info['tokens'][$token_type]['url'] = array(
'name' => t('URL'),
'description' => t('The URL of the @entity.', array('@entity' => backdrop_strtolower($entity_info['label']))),
'module' => 'token',
'type' => 'url',
);
}
// Add [entity:original] tokens if they do not already exist.
if (!isset($info['tokens'][$token_type]['original'])) {
$info['tokens'][$token_type]['original'] = array(
'name' => t('Original @entity', array('@entity' => backdrop_strtolower($entity_info['label']))),
'description' => t('The original @entity data if the @entity is being updated or saved.', array('@entity' => backdrop_strtolower($entity_info['label']))),
'module' => 'token',
'type' => $token_type,
);
}
}
}