You are here

class CasTestSubscriber in CAS 8

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

Class CasTestSubscriber.

Hierarchy

  • class \Drupal\cas_test\CasTestSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of CasTestSubscriber

1 string reference to 'CasTestSubscriber'
cas_test.services.yml in tests/modules/cas_test/cas_test.services.yml
tests/modules/cas_test/cas_test.services.yml
1 service uses CasTestSubscriber
cas_test.test_subscriber in tests/modules/cas_test/cas_test.services.yml
Drupal\cas_test\CasTestSubscriber

File

tests/modules/cas_test/src/CasTestSubscriber.php, line 13

Namespace

Drupal\cas_test
View source
class CasTestSubscriber implements EventSubscriberInterface {

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events[CasHelper::EVENT_PRE_REGISTER][] = [
      'onPreRegister',
      0,
    ];
    $events[CasHelper::EVENT_PRE_LOGIN][] = [
      'onPreLogin',
      0,
    ];
    return $events;
  }

  /**
   * Change the username of the user being registered.
   *
   * @param \Drupal\cas\Event\CasPreRegisterEvent $event
   *   The event.
   */
  public function onPreRegister(CasPreRegisterEvent $event) {

    // Add a prefix of "testing_" to the CAS username.
    $username = $event
      ->getDrupalUsername();
    $new_username = 'testing_' . $username;
    $event
      ->setDrupalUsername($new_username);
  }

  /**
   * Cancels the login.
   *
   * @param \Drupal\cas\Event\CasPreLoginEvent $event
   */
  public function onPreLogin(CasPreLoginEvent $event) {
    $flag = \Drupal::state()
      ->get('cas_test.flag');
    if ($flag === 'cancel without message') {
      $event
        ->cancelLogin();
    }
    elseif ($flag === 'cancel with message') {
      $event
        ->cancelLogin('Cancelled with a custom message.');
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CasTestSubscriber::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
CasTestSubscriber::onPreLogin public function Cancels the login.
CasTestSubscriber::onPreRegister public function Change the username of the user being registered.