foreach (\Drupal::routeMatch()->getParameters() as $entity) { if ($entity instanceof \Drupal\Core\Entity\EntityInterface) { // here $entity is your object } }