private function LdapUserAdminForm::syncMappingsFromForm in Lightweight Directory Access Protocol (LDAP) 8.3
Extract sync mappings array from mapping table in admin form.
Parameters
array $values: As $form_state['values'] from Drupal FormAPI.
string $direction: Direction to sync to.
Return value
array Returns the relevant mappings.
2 calls to LdapUserAdminForm::syncMappingsFromForm()
- LdapUserAdminForm::submitForm in ldap_user/
src/ Form/ LdapUserAdminForm.php - Form submission handler.
- LdapUserAdminForm::validateForm in ldap_user/
src/ Form/ LdapUserAdminForm.php - Form validation handler.
File
- ldap_user/
src/ Form/ LdapUserAdminForm.php, line 1058
Class
- LdapUserAdminForm
- Provides the form to configure user configuration and field mapping.
Namespace
Drupal\ldap_user\FormCode
private function syncMappingsFromForm(array $values, $direction) {
$mappings = [];
foreach ($values as $field_name => $value) {
$parts = explode('__', $field_name);
if ($parts[0] != 'mappings' || !isset($parts[1]) || $parts[1] != $direction) {
continue;
}
// These are our rows.
foreach ($value as $row_descriptor => $columns) {
if ($row_descriptor == 'second-header') {
continue;
}
$key = $direction == self::PROVISION_TO_DRUPAL ? $this
->sanitizeMachineName($columns['user_attr']) : $this
->sanitizeMachineName($columns['ldap_attr']);
// Only save if its configurable and has an LDAP and Drupal attributes.
// The others are optional.
if ($columns['configurable_to_drupal'] && $columns['ldap_attr'] && $columns['user_attr']) {
$mappings[$key] = [
'ldap_attr' => trim($columns['ldap_attr']),
'user_attr' => trim($columns['user_attr']),
'convert' => $columns['convert'],
'direction' => $direction,
'user_tokens' => isset($columns['user_tokens']) ? $columns['user_tokens'] : '',
'config_module' => 'ldap_user',
'prov_module' => 'ldap_user',
'enabled' => 1,
];
$syncEvents = $direction == self::PROVISION_TO_DRUPAL ? LdapConfiguration::provisionsDrupalEvents() : $this
->provisionsLdapEvents();
foreach ($syncEvents as $prov_event => $discard) {
if (isset($columns[$prov_event]) && $columns[$prov_event]) {
$mappings[$key]['prov_events'][] = $prov_event;
}
}
}
}
}
return $mappings;
}