You are here

protected function TokenReplacer::entityIsCurrentPage in Advanced Entity Tokens 2.x

Checks if the current page is the full page view of the passed-in entity.

Parameters

int $entity_id: An entity id.

string $id_key: The entity id key (e.g. nid for nodes, fid for files).

Return value

bool TRUE if yes; FALSE otherwise.

1 call to TokenReplacer::entityIsCurrentPage()
TokenReplacer::recursiveTokenUseDetected in src/TokenReplacer.php
Determines if recursive token use has been detected.

File

src/TokenReplacer.php, line 333

Class

TokenReplacer
Class TokenReplacer.

Namespace

Drupal\aet

Code

protected function entityIsCurrentPage($entity_id, $id_key) {

  // Returns the object of the entity being viewed.
  $page_entity = \Drupal::request()->attributes
    ->get('node');

  // Checks if no entity is being viewed or if it doesn't contain the property
  // with $id_key as it's key.
  if (empty($page_entity) || !isset($page_entity->{$id_key})) {

    // If the above check is true, then the passed-in entity is not being
    // viewed directly.
    return FALSE;
  }

  // Returns true if the id of the passed in entity is equal to the id of the
  // entity being viewed.
  return $page_entity->{$id_key} === $entity_id;
}