You are here

public static function RouteSubscriber::isViewing in Lightning Core 8.5

Same name and namespace in other branches
  1. 8 src/Routing/RouteSubscriber.php \Drupal\lightning_core\Routing\RouteSubscriber::isViewing()
  2. 8.2 src/Routing/RouteSubscriber.php \Drupal\lightning_core\Routing\RouteSubscriber::isViewing()
  3. 8.3 src/Routing/RouteSubscriber.php \Drupal\lightning_core\Routing\RouteSubscriber::isViewing()
  4. 8.4 src/Routing/RouteSubscriber.php \Drupal\lightning_core\Routing\RouteSubscriber::isViewing()

Checks if we are currently viewing an entity at its canonical route.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity.

\Drupal\Core\Routing\RouteMatchInterface $route_match: (optional) The current route match.

Return value

bool TRUE if we are at the entity's canonical route, FALSE otherwise.

File

src/Routing/RouteSubscriber.php, line 94

Class

RouteSubscriber
Dynamically alters various routes.

Namespace

Drupal\lightning_core\Routing

Code

public static function isViewing(EntityInterface $entity, RouteMatchInterface $route_match = NULL) {
  $route_match = $route_match ?: \Drupal::routeMatch();
  $entity_type = $entity
    ->getEntityTypeId();
  return $route_match
    ->getRouteName() == "entity.{$entity_type}.canonical" && $route_match
    ->getRawParameter($entity_type) == $entity
    ->id();
}