You are here

public function LdapUserProcessor::getProvisionRelatedLdapEntry in Lightweight Directory Access Protocol (LDAP) 8.3

Given a Drupal account, find the related LDAP entry.

Parameters

\Drupal\user\Entity\User $account: Drupal user account.

string|null $prov_events: Provisioning event.

Return value

bool|array False or LDAP entry

File

ldap_user/src/Processor/LdapUserProcessor.php, line 526

Class

LdapUserProcessor
Processor for LDAP provisioning.

Namespace

Drupal\ldap_user\Processor

Code

public function getProvisionRelatedLdapEntry(User $account, $prov_events = NULL) {
  if (!$prov_events) {
    $prov_events = LdapConfiguration::getAllEvents();
  }
  $sid = $this->config['ldapEntryProvisionServer'];
  if (!$sid) {
    return FALSE;
  }

  // $user_entity->ldap_user_prov_entries,.
  $factory = \Drupal::service('ldap.servers');

  /** @var \Drupal\ldap_servers\Entity\Server $ldap_server */
  $ldap_server = $factory
    ->getServerById($sid);
  $params = [
    'direction' => self::PROVISION_TO_LDAP,
    'prov_events' => $prov_events,
    'module' => 'ldap_user',
    'function' => 'getProvisionRelatedLdapEntry',
    'include_count' => FALSE,
  ];
  try {
    $proposed_ldap_entry = $this
      ->drupalUserToLdapEntry($account, $ldap_server, $params);
  } catch (\Exception $e) {
    \Drupal::logger('ldap_user')
      ->error('Unable to prepare LDAP entry: %message', [
      '%message',
      $e
        ->getMessage(),
    ]);
    return FALSE;
  }
  if (!(is_array($proposed_ldap_entry) && isset($proposed_ldap_entry['dn']) && $proposed_ldap_entry['dn'])) {
    return FALSE;
  }
  $ldap_entry = $ldap_server
    ->checkDnExistsIncludeData($proposed_ldap_entry['dn'], []);
  return $ldap_entry;
}