You are here

private function LdapEntryProvisionSubscriber::fetchDrupalAccountAttribute in Lightweight Directory Access Protocol (LDAP) 8.4

Fetch a single token.

Parameters

string $token: Token key.

1 call to LdapEntryProvisionSubscriber::fetchDrupalAccountAttribute()
LdapEntryProvisionSubscriber::fetchDrupalAttributeValue in ldap_user/src/EventSubscriber/LdapEntryProvisionSubscriber.php
Replace a single token.

File

ldap_user/src/EventSubscriber/LdapEntryProvisionSubscriber.php, line 309

Class

LdapEntryProvisionSubscriber
Event subscribers for creating and updating LDAP entries.

Namespace

Drupal\ldap_user\EventSubscriber

Code

private function fetchDrupalAccountAttribute(string $token) : void {

  // Trailing period to allow for empty value.
  [
    $attribute_type,
    $attribute_name,
    $attribute_conversion,
  ] = explode('.', $token . '.');
  $value = NULL;
  if ($attribute_type === 'field' || $attribute_type === 'property') {
    $value = $this
      ->fetchDrupalAccountField($attribute_name);
  }
  elseif ($attribute_type === 'password') {
    $value = $this
      ->fetchDrupalAccountPassword($attribute_name);
    if (empty($value)) {

      // Do not evaluate empty passwords, to avoid overwriting them.
      return;
    }
  }
  if ($attribute_conversion === 'to-md5') {
    $value = md5($value);
  }
  elseif ($attribute_conversion === 'to-lowercase') {
    $value = mb_strtolower($value);
  }
  $this->tokens[sprintf('[%s]', $token)] = $value;
}