protected function TokenReplacer::entityIsBeingViewed in Advanced Entity Tokens 2.x
Checks if an entity is being viewed.
Parameters
string $entity_type_id: The entity type ID.
string $entity_type_key: The entity type key (e.g. "nid").
$entity_id: The entity ID.
Return value
bool TRUE if the entity with $id as its id and of type $entity_type is being viewed.
1 call to TokenReplacer::entityIsBeingViewed()
- TokenReplacer::recursiveTokenUseDetected in src/
TokenReplacer.php - Determines if recursive token use has been detected.
File
- src/
TokenReplacer.php, line 366
Class
- TokenReplacer
- Class TokenReplacer.
Namespace
Drupal\aetCode
protected function entityIsBeingViewed(string $entity_type_id, string $entity_type_key, $entity_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_id . '_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) then return
// TRUE, which means the entity of the received ID is being viewed.
if ($entity_id == $entity->{$entity_type_key} || $entity_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;
}