You are here

public function ServerTestForm::testUserMapping in Lightweight Directory Access Protocol (LDAP) 8.4

Same name and namespace in other branches
  1. 8.3 ldap_servers/src/Form/ServerTestForm.php \Drupal\ldap_servers\Form\ServerTestForm::testUserMapping()

Test the user mappings.

Parameters

string $drupal_username: The Drupal username.

Return value

\Symfony\Component\Ldap\Entry|false Entry.

1 call to ServerTestForm::testUserMapping()
ServerTestForm::submitForm in ldap_servers/src/Form/ServerTestForm.php
This is the default entity object builder function. It is called before any other submit handler to build the new entity object to be used by the following submit handlers. At this point of the form workflow the entity is validated and the form state…

File

ldap_servers/src/Form/ServerTestForm.php, line 559

Class

ServerTestForm
Use Drupal\Core\Form\FormBase;.

Namespace

Drupal\ldap_servers\Form

Code

public function testUserMapping(string $drupal_username) {
  $this->ldapGroupManager
    ->setServerById($this->ldapServer
    ->id());
  $ldap_user = $this->ldapGroupManager
    ->matchUsernameToExistingLdapEntry($drupal_username);
  if ($ldap_user) {
    $this->resultsTables['basic'][] = [
      'class' => 'color-success',
      'data' => [
        $this
          ->t('Found test user %username by searching on  %user_attr = %username.', [
          '%username' => $drupal_username,
          '%user_attr' => $this->ldapServer
            ->getAuthenticationNameAttribute(),
        ]),
      ],
    ];
  }
  else {
    $this->resultsTables['basic'][] = [
      'class' => 'color-error',
      'data' => [
        $this
          ->t('Failed to find test user %username by searching on %user_attr = %username.', [
          '%username' => $drupal_username,
          '%user_attr' => $this->ldapServer
            ->getAuthenticationNameAttribute(),
        ]),
      ],
    ];
    $this->exception = TRUE;
  }
  return $ldap_user;
}