You are here

public function CertificateRoutes::routes in Certificate 4.x

1 string reference to 'CertificateRoutes::routes'
certificate.routing.yml in ./certificate.routing.yml
certificate.routing.yml

File

src/Routing/CertificateRoutes.php, line 16

Class

CertificateRoutes
Defines dynamic routes.

Namespace

Drupal\certificate\Routing

Code

public function routes() {
  $routes = [];
  foreach (certificate_get_entity_types() ?? [] as $entity_type) {
    $options = [
      'no_cache' => 'TRUE',
      'certificate_param' => $entity_type,
    ];

    // Entity tab
    // @todo it is not always entity_type/id/certificate, we need to pull from
    // the entity type's canonical URL.
    $tab_route = new Route("{$entity_type}/{{$entity_type}}/certificate");
    $tab_route
      ->setDefault('_controller', '\\Drupal\\certificate\\Controller\\CertificateController::certificatePage');
    $tab_route
      ->setDefault('_title', 'Certificate');
    $tab_route
      ->setOptions($options);
    $tab_route
      ->setRequirements([
      '_custom_access' => '\\Drupal\\certificate\\Controller\\CertificateController::accessTab',
    ]);
    $routes["certificate.{$entity_type}"] = $tab_route;
    $pdf_route = new Route("{$entity_type}/{{$entity_type}}/certificate/{user}/{certificate_template}/pdf");
    $pdf_route
      ->setDefault('_controller', '\\Drupal\\certificate\\Controller\\CertificateController::certificateDownload');
    $pdf_route
      ->setDefault('_title', 'Download');
    $pdf_route
      ->setOptions($options);
    $pdf_route
      ->setOption('params', [
      'user' => 'type: entity:user',
      'certificate_template' => 'type: entity:certificate_template',
    ]);
    $pdf_route
      ->setRequirements([
      '_custom_access' => '\\Drupal\\certificate\\Controller\\CertificateController::accessPdf',
    ]);
    $routes["certificate.{$entity_type}.pdf"] = $pdf_route;
  }
  return $routes;
}