You are here

public function UserSyncEventSubscriber::getAttributeByConfig in SAML Authentication 4.x

Same name and namespace in other branches
  1. 8.3 src/EventSubscriber/UserSyncEventSubscriber.php \Drupal\samlauth\EventSubscriber\UserSyncEventSubscriber::getAttributeByConfig()
  2. 8.2 src/EventSubscriber/UserSyncEventSubscriber.php \Drupal\samlauth\EventSubscriber\UserSyncEventSubscriber::getAttributeByConfig()

Returns value from a SAML attribute whose name is configured in our module.

This is suitable for single-value attributes. (Most values are.)

Parameters

string $config_key: A key in the module's configuration, containing the name of a SAML attribute.

\Drupal\samlauth\Event\SamlauthUserSyncEvent $event: The event, which holds the attributes from the SAML response.

Return value

mixed|null The SAML attribute value; NULL if the attribute value was not found.

1 call to UserSyncEventSubscriber::getAttributeByConfig()
UserSyncEventSubscriber::onUserSync in src/EventSubscriber/UserSyncEventSubscriber.php
Performs actions to synchronize users with SAML data on login.

File

src/EventSubscriber/UserSyncEventSubscriber.php, line 233

Class

UserSyncEventSubscriber
Event subscriber that synchronizes user properties on a user_sync event.

Namespace

Drupal\samlauth\EventSubscriber

Code

public function getAttributeByConfig($config_key, SamlauthUserSyncEvent $event) {
  $attributes = $event
    ->getAttributes();
  $attribute_name = $this->config
    ->get($config_key);
  return $attribute_name && !empty($attributes[$attribute_name][0]) ? $attributes[$attribute_name][0] : NULL;
}