You are here

class CasUserInteractionTestSubscriber in CAS 8

Same name and namespace in other branches
  1. 2.x tests/modules/cas_user_interaction_test/src/CasUserInteractionTestSubscriber.php \Drupal\cas_user_interaction_test\CasUserInteractionTestSubscriber

Class CasTestSubscriber.

Hierarchy

Expanded class hierarchy of CasUserInteractionTestSubscriber

1 string reference to 'CasUserInteractionTestSubscriber'
cas_user_interaction_test.services.yml in tests/modules/cas_user_interaction_test/cas_user_interaction_test.services.yml
tests/modules/cas_user_interaction_test/cas_user_interaction_test.services.yml
1 service uses CasUserInteractionTestSubscriber
cas_user_interaction_test.subscriber in tests/modules/cas_user_interaction_test/cas_user_interaction_test.services.yml
Drupal\cas_user_interaction_test\CasUserInteractionTestSubscriber

File

tests/modules/cas_user_interaction_test/src/CasUserInteractionTestSubscriber.php, line 14

Namespace

Drupal\cas_user_interaction_test
View source
class CasUserInteractionTestSubscriber implements EventSubscriberInterface {

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    return [
      CasHelper::EVENT_PRE_USER_LOAD_REDIRECT => 'onPreUserLoadRedirect',
    ];
  }

  /**
   * Redirects to a form that asks user to accept the site's 'Legal Notice'.
   *
   * @param \Drupal\cas\Event\CasPreUserLoadRedirectEvent $event
   *   The event.
   */
  public function onPreUserLoadRedirect(CasPreUserLoadRedirectEvent $event) {
    $is_legal_notice_changed = \Drupal::state()
      ->get('cas_user_interaction_test.changed', FALSE);
    $local_account = \Drupal::service('externalauth.externalauth')
      ->load($event
      ->getPropertyBag()
      ->getUsername(), 'cas');

    // Add a redirect only if a local account exists (i.e. it's a login
    // operation) and the site's 'Legal Notice' has changed.
    if ($local_account && $is_legal_notice_changed) {

      /** @var \Drupal\Core\TempStore\PrivateTempStore $tempstore */
      $tempstore = \Drupal::service('tempstore.private')
        ->get('cas_user_interaction_test');
      $tempstore
        ->set('ticket', $event
        ->getTicket());
      $tempstore
        ->set('property_bag', $event
        ->getPropertyBag());
      $event
        ->setRedirectResponse(new RedirectResponse(Url::fromRoute('cas_user_interaction_test.form')
        ->toString()));
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CasUserInteractionTestSubscriber::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
CasUserInteractionTestSubscriber::onPreUserLoadRedirect public function Redirects to a form that asks user to accept the site's 'Legal Notice'.