function aet_entity_is_viewed in Advanced Entity Tokens 7
Checks if an entity is being viewed.
Return value
bool TRUE if the entity with $id as its id and of type $entity_type is being viewed.
1 call to aet_entity_is_viewed()
- _aet_entity_tokens in ./
aet.tokens.inc - INTERNAL implementation of hook_tokens specified for entities.
File
- ./
aet.module, line 53 - The AET main module file.
Code
function aet_entity_is_viewed($entity_type, $id_key, $id) {
// Get the function backtrace to check if the the entity view function is
// part of the chain.
$backtrace = debug_backtrace();
foreach ($backtrace as $caller) {
if ($caller['function'] === $entity_type . '_view') {
// Move the $entity object to a new variable to increase readability.
$entity = $caller['args'][0];
// If the received id matches the viewed entity id (or uuid) than
// return TRUE, which means the entity of the received id is being viewed.
if ($id == $entity->{$id_key} || AET_UUID && $id == $entity->uuid) {
return TRUE;
}
}
elseif ($caller['function'] == '_drupal_bootstrap_full' || $caller == 'menu_execute_active_handler') {
// There is no point in going back this far, so just stop.
break;
}
}
return FALSE;
}