You are here

private function DrupalUserProcessor::setUserDefinedMappings in Lightweight Directory Access Protocol (LDAP) 8.3

Same name and namespace in other branches
  1. 8.4 ldap_user/src/Processor/DrupalUserProcessor.php \Drupal\ldap_user\Processor\DrupalUserProcessor::setUserDefinedMappings()

Sets the additional, user-defined fields.

The greyed out user mappings are not passed to this function.

Parameters

array $ldapUser: Ldap user data.

string $direction: Provision direction.

array $prov_events: Provisioning event.

1 call to DrupalUserProcessor::setUserDefinedMappings()
DrupalUserProcessor::applyAttributesToAccount in ldap_user/src/Processor/DrupalUserProcessor.php
Apply field values to user account.

File

ldap_user/src/Processor/DrupalUserProcessor.php, line 1146

Class

DrupalUserProcessor
Handles processing of a user from LDAP to Drupal.

Namespace

Drupal\ldap_user\Processor

Code

private function setUserDefinedMappings(array $ldapUser, $direction, array $prov_events) {
  $mappingHelper = new SyncMappingHelper();

  // Get any additional mappings.
  $mappings = $mappingHelper
    ->getSyncMappings($direction, $prov_events);

  // Loop over the mappings.
  foreach ($mappings as $key => $fieldDetails) {

    // Make sure this mapping is relevant to the sync context.
    if ($mappingHelper
      ->isSynced($key, $prov_events, $direction)) {

      // If "convert from binary is selected" and no particular method is in
      // token default to binaryConversionToString() function.
      if ($fieldDetails['convert'] && strpos($fieldDetails['ldap_attr'], ';') === FALSE) {
        $fieldDetails['ldap_attr'] = str_replace(']', ';binary]', $fieldDetails['ldap_attr']);
      }
      $value = $this->tokenProcessor
        ->tokenReplace($ldapUser['attr'], $fieldDetails['ldap_attr'], 'ldap_entry');

      // The ordinal $value_instance is not used and could probably be
      // removed.
      list($value_type, $value_name, $value_instance) = $this
        ->parseUserAttributeNames($key);
      if ($value_type == 'field' || $value_type == 'property') {
        $this->account
          ->set($value_name, $value);
      }
    }
  }
}