function aet_token_info in Advanced Entity Tokens 7
Same name and namespace in other branches
- 2.x aet.module \aet_token_info()
Implements hook_token_info().
Declaring the AET tokens.
File
- ./
aet.tokens.inc, line 12 - Token callbacks for the AET module.
Code
function aet_token_info() {
// Initializing the $info array.
$info = array(
'types' => array(),
'tokens' => array(),
);
$info['types']['aet'] = array();
$info['types']['aet']['name'] = t('Advanced Entity Tokens');
$info['types']['aet']['description'] = t('AET Description');
// Getting the information arrays on all the entities.
$entities = entity_get_info();
// Looping the entity information array to add the token types.
foreach ($entities as $entity_type => $entity_info) {
$token_type = !empty($entity_info['token type']) ? $entity_info['token type'] : $entity_type;
if (empty($info['types'])) {
$info['types'] = array();
}
if (empty($info['tokens'])) {
$info['tokens'] = array();
}
$entity_id_key = $entity_info['entity keys']['id'];
// Adding the entity element token.
// The token key consists of the entity key id and a question mark
// to mark this as the place to enter the entity's id.
$info['tokens']['aet'][$token_type] = array();
$info['tokens']['aet'][$token_type]['name'] = 'AET ' . $entity_info['label'] . ' entity';
$info['tokens']['aet'][$token_type]['description'] = t("Reference a @entity_name entity by using it's @id_key", array(
'@entity_name' => $entity_info['label'],
'@id_key' => $entity_id_key,
));
$info['tokens']['aet'][$token_type]['dynamic'] = TRUE;
$info['tokens']['aet'][$token_type]['type'] = $token_type;
}
return $info;
}