function addresssfield_get_token_entity_mapping in Address Field 7
Return an array of entity type to token type mappings. (Stolen from the token module).
Why do we need this? Because when the token API was moved to core we did not re-use the entity type as the base name for taxonomy terms and vocabulary tokens.
See also
1 call to addresssfield_get_token_entity_mapping()
- addressfield_tokens in ./
addressfield.tokens.inc - Implements hook_tokens().
File
- ./
addressfield.tokens.inc, line 278 - Token module integration.
Code
function addresssfield_get_token_entity_mapping($value_type = 'token', $value = NULL, $fallback = FALSE) {
if (module_exists('token')) {
return token_get_entity_mapping($value_type, $value, $fallback);
}
$mapping =& drupal_static(__FUNCTION__, array());
if (empty($mapping)) {
foreach (entity_get_info() as $entity_type => $info) {
$mapping[$entity_type] = !empty($info['token type']) ? $info['token type'] : $entity_type;
}
// Allow modules to alter the mapping array.
drupal_alter('token_entity_mapping', $mapping);
}
if (!isset($value)) {
return $value_type == 'token' ? array_flip($mapping) : $mapping;
}
elseif ($value_type == 'token') {
$return = array_search($value, $mapping);
return $return !== FALSE ? $return : ($fallback ? $value : FALSE);
}
elseif ($value_type == 'entity') {
return isset($mapping[$value]) ? $mapping[$value] : ($fallback ? $value : FALSE);
}
}