You are here

private function FieldProvider::addPuidFields in Lightweight Directory Access Protocol (LDAP) 8.4

Add PUID Fields.

These 4 user fields identify where in LDAP and which LDAP server they are associated with. They are required for a Drupal account to be "LDAP associated" regardless of if any other fields/properties are provisioned or synced.

1 call to FieldProvider::addPuidFields()
FieldProvider::loadAttributes in ldap_user/src/FieldProvider.php
LDAP attributes to alter.

File

ldap_user/src/FieldProvider.php, line 245

Class

FieldProvider
Provides the basic and required fields needed for user mappings.

Namespace

Drupal\ldap_user

Code

private function addPuidFields() : void {
  $url = Url::fromRoute('entity.ldap_server.collection');

  // A plain $url->toString() call in some places (early in the request)
  // can cause Drupal to throw a 'leaked metadata' exception. To prevent
  // toString() from handling any metadata in the background, we pass TRUE.
  $url_string = $url
    ->toString(TRUE)
    ->getGeneratedUrl();
  $tokens = [
    '%edit_link' => Link::fromTextAndUrl($url_string, $url)
      ->toString(),
    '%sid' => $this->server
      ->id(),
  ];
  $fields = [
    '[field.ldap_user_puid_sid]' => $this
      ->t('Field: sid providing PUID'),
    '[field.ldap_user_puid]' => $this
      ->t('Field: PUID'),
    '[field.ldap_user_puid_property]' => $this
      ->t('Field: PUID Attribute'),
  ];
  foreach ($fields as $key => $name) {
    $this->attributes[$key] = new Mapping($key, (string) $name, FALSE, TRUE, [
      self::EVENT_CREATE_DRUPAL_USER,
    ], 'ldap_user', 'ldap_servers');
    $this->attributes[$key]
      ->setNotes((string) $this
      ->t('configure at %edit_link', $tokens));
  }
  $this->attributes['[field.ldap_user_puid_sid]']
    ->setLdapAttribute($this->server
    ->id());
  $this->attributes['[field.ldap_user_puid]']
    ->setLdapAttribute($this
    ->addTokens($this->server
    ->getUniquePersistentAttribute()));
  $this->attributes['[field.ldap_user_puid_property]']
    ->setLdapAttribute($this->server
    ->getUniquePersistentAttribute());
}