You are here

public function CertificateController::getEntityFromRoute in Certificate 4.x

Get the certificate enabled entity from the route.

Return value

\Drupal\Core\Entity\ContentEntityInterface

4 calls to CertificateController::getEntityFromRoute()
CertificateController::accessPdf in src/Controller/CertificateController.php
Downloads
CertificateController::accessTab in src/Controller/CertificateController.php
CertificateController::certificateDownload in src/Controller/CertificateController.php
Stream a PDF to the browser.
CertificateController::certificatePage in src/Controller/CertificateController.php
Full tab

File

src/Controller/CertificateController.php, line 26

Class

CertificateController

Namespace

Drupal\certificate\Controller

Code

public function getEntityFromRoute() {
  $param = current(\Drupal::routeMatch()
    ->getParameters());
  if (current($param) instanceof EntityInterface) {
    $entity = current($param);
  }
  if (!isset($entity)) {
    $route_match = Drupal::routeMatch();
    $route = $route_match
      ->getRouteObject();
    if ($certificate_param = $route
      ->getOption('certificate_param')) {
      $params = $route_match
        ->getParameters();
      $entity_id = $params
        ->get($certificate_param);
      $entity = Drupal::entityTypeManager()
        ->getStorage($certificate_param)
        ->load($entity_id);
    }
  }
  return $entity ?? NULL;
}