You are here

public function ChecklistapiRoutes::routes in Checklist API 8

Provides dynamic routes.

Return value

\Symfony\Component\Routing\Route[] An array of route objects.

1 string reference to 'ChecklistapiRoutes::routes'
checklistapi.routing.yml in ./checklistapi.routing.yml
checklistapi.routing.yml

File

src/Routing/ChecklistapiRoutes.php, line 18

Class

ChecklistapiRoutes
Provides routes for checklists.

Namespace

Drupal\checklistapi\Routing

Code

public function routes() {
  $routes = [];
  $definitions = \Drupal::moduleHandler()
    ->invokeAll('checklistapi_checklist_info');
  foreach ($definitions as $id => $definition) {

    // Ignore incomplete definitions.
    if (empty($definition['#path']) || empty($definition['#title'])) {
      continue;
    }
    $requirements = [
      '_checklistapi_access' => 'TRUE',
    ];

    // View/edit checklist.
    $routes["checklistapi.checklists.{$id}"] = new Route($definition['#path'], [
      '_title' => (string) $definition['#title'],
      '_form' => '\\Drupal\\checklistapi\\Form\\ChecklistapiChecklistForm',
      'checklist_id' => $id,
      'op' => 'any',
    ], $requirements);

    // Clear saved progress.
    $routes["checklistapi.checklists.{$id}.clear"] = new Route("{$definition['#path']}/clear", [
      '_title' => 'Clear',
      '_form' => '\\Drupal\\checklistapi\\Form\\ChecklistapiChecklistClearForm',
      'checklist_id' => $id,
      'op' => 'edit',
    ], $requirements);
  }
  return $routes;
}