You are here

public function ConfigPagesRoutes::routes in Config Pages 8.2

Same name and namespace in other branches
  1. 8.3 src/Routing/ConfigPagesRoutes.php \Drupal\config_pages\Routing\ConfigPagesRoutes::routes()
  2. 8 src/Routing/ConfigPagesRoutes.php \Drupal\config_pages\Routing\ConfigPagesRoutes::routes()
1 string reference to 'ConfigPagesRoutes::routes'
config_pages.routing.yml in ./config_pages.routing.yml
config_pages.routing.yml

File

src/Routing/ConfigPagesRoutes.php, line 16

Class

ConfigPagesRoutes
Defines dynamic routes for Config Pages.

Namespace

Drupal\config_pages\Routing

Code

public function routes() {
  $routes = [];

  // Declare dynamic routes for config pages entities.
  $types = ConfigPagesType::loadMultiple();
  foreach ($types as $cp_type) {
    $bundle = $cp_type
      ->id();
    $label = $cp_type
      ->get('label');
    $menu = $cp_type
      ->get('menu');
    $path = isset($menu['path']) ? $menu['path'] : '';
    if (!$path) {

      // Use module pre-defined path in case of user left menu item empty.
      $path = '/admin/structure/config_pages/' . $cp_type
        ->id();
    }
    $routes['config_pages.' . $bundle] = new Route($path, [
      '_controller' => '\\Drupal\\config_pages\\Controller\\ConfigPagesController::classInit',
      'config_pages_type' => $bundle,
      '_title_callback' => '\\Drupal\\config_pages\\Controller\\ConfigPagesController::getPageTitle',
      'label' => $label,
    ], [
      '_permission' => 'edit config_pages entity+edit ' . $cp_type
        ->id() . ' config page entity',
    ], [
      '_admin_route' => TRUE,
    ]);
  }
  return $routes;
}