function aet_tokens in Advanced Entity Tokens 7
Same name and namespace in other branches
- 2.x aet.module \aet_tokens()
This is the main implementation of hook_tokens.
The main purpose of this hook implementation is to identify the entity type and call aet_entity_token on it.
Parameters
string $type: The tokens type.
array $tokens: A list of tokens to replace.
array $data: Additional data for this function (e.g. an entity object). This function doesn't need additional data though.
array $options: An associative array of options for token replacement; see token_replace() for possible values.
File
- ./
aet.tokens.inc, line 84 - Token callbacks for the AET module.
Code
function aet_tokens($type, $tokens, array $data = array(), array $options = array()) {
// Initiating the $replacements array.
$replacements = array();
// TODO Add support $options['callback']
// TODO Add support $options['sanitize']
// TODO Add support $options['language']
$options += _aet_default_options();
// Only tokens from the aet type are supported.
if ($type === 'aet') {
// Gets the information array on all the available entities in this drupal
// site.
$entities = entity_get_info();
// Loops the $entities array to check if they exist in the $tokens array.
foreach ($entities as $entity_type => $entity_info) {
$token_type = !empty($entity_info['token type']) ? $entity_info['token type'] : $entity_type;
$data += array(
'entity_type' => $entity_type,
);
// The aet_entity_tokens function replaces the next level of the aet
// tokens.
// E.G. [aet:node:1], [aet:node:label]
$replacements += _aet_entity_tokens($token_type, token_find_with_prefix($tokens, $token_type), $data, $options);
}
// Calls aet_clear_tokens to clear unreplaced tokens if the option is
// flagged.
aet_clear_tokens($tokens, $replacements, $options['clear']);
}
// Returns the $replacements array.
return $replacements;
}