You are here

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

Populate LDAP entry array for provisioning.

Parameters

string $prov_event: Provisioning event.

Return value

\Symfony\Component\Ldap\Entry Entry to send *to* LDAP.

2 calls to LdapEntryProvisionSubscriber::buildLdapEntry()
LdapEntryProvisionSubscriber::provisionLdapEntry in ldap_user/src/EventSubscriber/LdapEntryProvisionSubscriber.php
Provision an LDAP entry if none exists.
LdapEntryProvisionSubscriber::syncToLdapEntry in ldap_user/src/EventSubscriber/LdapEntryProvisionSubscriber.php
Given a Drupal account, sync to related LDAP entry.

File

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

Class

LdapEntryProvisionSubscriber
Event subscribers for creating and updating LDAP entries.

Namespace

Drupal\ldap_user\EventSubscriber

Code

private function buildLdapEntry(string $prov_event) : Entry {
  $dn = '';
  $attributes = [];
  if (!is_object($this->account) || !is_object($this->ldapServer)) {
    throw new LdapBadParamsException('Missing user or server.');
  }
  $this->fieldProvider
    ->loadAttributes(self::PROVISION_TO_LDAP, $this->ldapServer);
  $mappings = $this->fieldProvider
    ->getAttributesSyncedOnEvent($prov_event);
  foreach ($mappings as $field) {

    // @todo Trimming here shows that we should not be saving the brackets to
    // the database.
    $ldap_attribute_name = trim($field
      ->getLdapAttribute(), '[]');
    $attribute = $field
      ->getDrupalAttribute() === 'user_tokens' ? $field
      ->getUserTokens() : $field
      ->getDrupalAttribute();
    $value = $this
      ->fetchDrupalAttributeValue($attribute, $ldap_attribute_name);
    if ($value) {
      if ($ldap_attribute_name === 'dn') {
        $dn = $value;
      }
      else {
        $attributes[$ldap_attribute_name][] = $value;
      }
    }
  }
  $entry = new Entry($dn, $attributes);

  // Allow other modules to alter $ldap_user.
  $params = [
    'prov_events' => $prov_event,
    'direction' => self::PROVISION_TO_LDAP,
  ];
  $this->moduleHandler
    ->alter('ldap_entry', $entry, $params);
  return $entry;
}