You are here

protected function LdapUserMappingBaseForm::syncMappingsFromForm in Lightweight Directory Access Protocol (LDAP) 8.4

Extract sync mappings array from mapping table in admin form.

Parameters

array $values: Form values.

Return value

array Returns the relevant mappings.

2 calls to LdapUserMappingBaseForm::syncMappingsFromForm()
LdapUserMappingBaseForm::submitForm in ldap_user/src/Form/LdapUserMappingBaseForm.php
Form submission handler.
LdapUserMappingBaseForm::validateForm in ldap_user/src/Form/LdapUserMappingBaseForm.php
Form validation handler.

File

ldap_user/src/Form/LdapUserMappingBaseForm.php, line 206

Class

LdapUserMappingBaseForm
Provides the form to configure user configuration and field mapping.

Namespace

Drupal\ldap_user\Form

Code

protected function syncMappingsFromForm(array $values) : array {
  $mappings = [];
  foreach ($values['mappings'] as $row) {
    if (isset($row['source']) && !empty($row['source']) && $row['configured_mapping'] == TRUE && $row['delete'] == FALSE) {
      $events = [];
      foreach ($this->events as $event) {
        if ($row[$event] == 1) {
          $events[] = $event;
        }
      }
      $mapping = new Mapping($row['target'], (string) $this
        ->t('User defined mapping for @field', [
        '@field' => $row['target'],
      ]), TRUE, TRUE, $events, 'ldap_user', 'ldap_user');
      $mapping
        ->convertBinary((bool) $row['convert']);
      if (!empty($row['user_tokens'])) {
        $mapping
          ->setUserTokens(trim($row['user_tokens']));
      }
      $this
        ->setSpecificMapping($mapping, $row);
      $mappings[$this
        ->sanitizeMachineName($row['target'])] = $mapping
        ->serialize();
    }
  }
  return $mappings;
}