You are here

BakeryRoutes.php in Bakery Single Sign-On System 8.2

File

src/Routing/BakeryRoutes.php
View source
<?php

namespace Drupal\bakery\Routing;

use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Routing\RouteCompiler;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;

/**
 * Defines dynamic routes.
 */
class BakeryRoutes implements ContainerInjectionInterface {

  /**
   * @var \Drupal\Core\Config\ImmutableConfig
   */
  protected $config;
  public function __construct(ConfigFactoryInterface $config_factory) {
    $this->config = $config_factory
      ->get('bakery.settings');
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('config.factory'));
  }

  /**
   * {@inheritdoc}
   */
  public function routes() {
    $routes = new RouteCollection();
    $subsite_login = $this->config
      ->get('subsite_login');
    if (empty($this->config
      ->get('bakery_key'))) {

      // Without a key nothing works so don't expose any dynamic routes.
    }
    elseif ($this->config
      ->get('bakery_is_master')) {
      if ($subsite_login) {
        $routes
          ->add('bakery.register', new Route('/bakery', [
          '_controller' => '\\Drupal\\bakery\\Controller\\MainDeprecatedController::register',
          '_title' => 'Register',
        ], [
          '_custom_access' => '\\Drupal\\bakery\\Controller\\MainDeprecatedController::userIsAnonymous',
        ]));
        $routes
          ->add('bakery.login', new Route('/bakery/login', [
          '_controller' => '\\Drupal\\bakery\\Controller\\MainDeprecatedController::login',
          '_title' => 'Login',
        ], [
          '_access' => 'TRUE',
        ]));
      }
      $routes
        ->add('bakery.create', new Route('/bakery/create', [
        '_controller' => '\\Drupal\\bakery\\Controller\\MainController::eatGingerbreadCookie',
        '_title' => 'Bakery create',
      ], [
        '_custom_access' => '\\Drupal\\bakery\\Controller\\MainController::tasteGingerbreadCookie',
      ]));
    }
    else {
      if ($subsite_login) {
        $routes
          ->add('bakery.register', new Route('/bakery', [
          '_controller' => '\\Drupal\\bakery\\Controller\\ChildDeprecatedController::registerReturn',
          '_title' => 'Register',
        ], [
          '_access' => 'TRUE',
        ]));
        $routes
          ->add('bakery.create', new Route('/bakery/login', [
          '_controller' => '\\Drupal\\bakery\\Controller\\ChildDeprecatedController::loginReturn',
          '_title' => 'Login',
        ], [
          '_access' => 'TRUE',
        ]));
      }
      $routes
        ->add('bakery.update', new Route('/bakery/update', [
        '_controller' => '\\Drupal\\bakery\\Controller\\ChildController::eatStroopwafelCookie',
        '_title' => 'Update',
      ], [
        '_custom_access' => '\\Drupal\\bakery\\Controller\\ChildController::tasteStroopwafelCookie',
      ]));
      $routes
        ->add('bakery.repair', new Route('/bakery/repair', [
        '_form' => '\\Drupal\\bakery\\Forms\\BakeryUncrumbleForm',
        '_title' => 'Repair account',
      ], [
        '_custom_access' => '\\Drupal\\bakery\\Forms\\BakeryUncrumbleForm::uncrumbleAccess',
      ]));
      $routes
        ->add('bakery.pull', new Route('/admin/config/people/bakery', [
        '_form' => '\\Drupal\\bakery\\Forms\\BakeryPullForm',
        '_title' => 'Pull Bakery user',
      ], [
        '_permission' => 'administer users',
      ]));
    }
    $routes
      ->addOptions([
      'compiler_class' => RouteCompiler::class,
    ]);
    return $routes;
  }

}

Classes

Namesort descending Description
BakeryRoutes Defines dynamic routes.