You are here

public function CasRouteEnhancer::enhance in CAS 2.x

Same name and namespace in other branches
  1. 8 src/Routing/CasRouteEnhancer.php \Drupal\cas\Routing\CasRouteEnhancer::enhance()

Updates the defaults for a route definition based on the request.

Parameters

array $defaults: The defaults, maps to '_defaults' in the route definition YAML.

\Symfony\Component\HttpFoundation\Request $request: The Request instance.

Return value

array The modified defaults. Each enhancer MUST return the $defaults but may add or remove values.

Overrides EnhancerInterface::enhance

File

src/Routing/CasRouteEnhancer.php, line 40

Class

CasRouteEnhancer
Class CasRouteEnhancer.

Namespace

Drupal\cas\Routing

Code

public function enhance(array $defaults, Request $request) {
  $route = $defaults[RouteObjectInterface::ROUTE_OBJECT];
  if ($route
    ->getPath() == '/user/logout') {

    // Replace the logout controller with our own if the logged in user logged
    // in using CAS and if we're configured to perform a CAS server logout
    // during normal Drupal logouts. Overriding the controller allows us to
    // redirect the user to the CAS server logout after logging out locally.
    if ($this->settings
      ->get('logout.cas_logout') && $request
      ->getSession() && $request
      ->getSession()
      ->get('is_cas_user')) {
      $defaults['_controller'] = '\\Drupal\\cas\\Controller\\LogoutController::logout';
    }
  }
  return $defaults;
}