You are here

class CasAutoAssignRolesSubscriber in CAS 8

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

Provides a CasAutoAssignRoleSubscriber.

Hierarchy

Expanded class hierarchy of CasAutoAssignRolesSubscriber

1 string reference to 'CasAutoAssignRolesSubscriber'
cas.services.yml in ./cas.services.yml
cas.services.yml
1 service uses CasAutoAssignRolesSubscriber
cas.auto_assign_roles_subscriber in ./cas.services.yml
Drupal\cas\Subscriber\CasAutoAssignRolesSubscriber

File

src/Subscriber/CasAutoAssignRolesSubscriber.php, line 13

Namespace

Drupal\cas\Subscriber
View source
class CasAutoAssignRolesSubscriber implements EventSubscriberInterface {

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

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

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

  /**
   * The entry point for our subscriber.
   *
   * Assign roles to a user that just registered via CAS.
   *
   * @param \Drupal\cas\Event\CasPreRegisterEvent $event
   *   The event object.
   */
  public function assignRolesOnRegistration(CasPreRegisterEvent $event) {
    $auto_assigned_roles = $this->settings
      ->get('user_accounts.auto_assigned_roles');
    if (!empty($auto_assigned_roles)) {
      $event
        ->setPropertyValue('roles', $auto_assigned_roles);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CasAutoAssignRolesSubscriber::$settings protected property Stores settings object.
CasAutoAssignRolesSubscriber::assignRolesOnRegistration public function The entry point for our subscriber.
CasAutoAssignRolesSubscriber::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
CasAutoAssignRolesSubscriber::__construct public function CasAutoAssignRoleSubscriber constructor.