You are here

class CasRouteEnhancer in CAS 8

Same name and namespace in other branches
  1. 2.x src/Routing/CasRouteEnhancer.php \Drupal\cas\Routing\CasRouteEnhancer

Class CasRouteEnhancer.

Override the default logout controller action with our own.

Our controller action will log the user out of Drupal and then redirect to the CAS server logout page as well.

Hierarchy

Expanded class hierarchy of CasRouteEnhancer

1 file declares its use of CasRouteEnhancer
CasRouteEnhancerTest.php in tests/src/Unit/Routing/CasRouteEnhancerTest.php
1 string reference to 'CasRouteEnhancer'
cas.services.yml in ./cas.services.yml
cas.services.yml
1 service uses CasRouteEnhancer
cas.route_enhancer in ./cas.services.yml
Drupal\cas\Routing\CasRouteEnhancer

File

src/Routing/CasRouteEnhancer.php, line 18

Namespace

Drupal\cas\Routing
View source
class CasRouteEnhancer implements EnhancerInterface {

  /**
   * Stores settings object.
   *
   * @var \Drupal\Core\Config\Config
   */
  protected $settings;

  /**
   * Constructor.
   *
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The config factory.
   */
  public function __construct(ConfigFactoryInterface $config_factory) {
    $this->settings = $config_factory
      ->get('cas.settings');
  }

  /**
   * {@inheritdoc}
   */
  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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CasRouteEnhancer::$settings protected property Stores settings object.
CasRouteEnhancer::enhance public function Update the defaults based on its own data and the request.
CasRouteEnhancer::__construct public function Constructor.