public function LdapUserConfAdmin::drupalFormValidate in Lightweight Directory Access Protocol (LDAP) 7.2
Same name and namespace in other branches
- 8.2 ldap_user/LdapUserConfAdmin.class.php \LdapUserConfAdmin::drupalFormValidate()
Validate submitted form.
Parameters
array $values: as $form_state['values'] from drupal form api.
array $storage: as $form_state['storage'] from drupal form api.
Return value
array in form array($errors, $warnings)to be thrown by form api
File
- ldap_user/
LdapUserConfAdmin.class.php, line 394
Class
Code
public function drupalFormValidate($values, $storage) {
$this
->populateFromDrupalForm($values, $storage);
list($errors, $warnings) = $this
->validate($values);
$this
->checkPuidOrphans($values['drupalAcctProvisionServer'], $values['orphanedDrupalAcctBehavior']);
// Since failed mapping rows in form, don't populate ->ldapUserSynchMappings, need to validate these from values.
foreach ($values as $field => $value) {
$parts = explode('__', $field);
// Since synch mapping fields are in n-tuples, process entire n-tuple at once (on field == configurable_to_drupal)
if (count($parts) != 4 || $parts[1] !== 'sm' || $parts[2] != 'configurable_to_drupal') {
continue;
}
list($direction, $discard, $column_name, $i) = $parts;
$action = $storage['synch_mapping_fields'][$direction][$i]['action'];
$tokens = [];
$row_mappings = [];
foreach ([
'remove',
'configurable_to_drupal',
'configurable_to_ldap',
'convert',
'direction',
'ldap_attr',
'user_attr',
'user_tokens',
] as $column_name) {
$input_name = join('__', [
'sm',
$column_name,
$i,
]);
$row_mappings[$column_name] = isset($values[$input_name]) ? $values[$input_name] : NULL;
}
$has_values = $row_mappings['ldap_attr'] || $row_mappings['user_attr'];
if ($has_values) {
$tokens['%ldap_attr'] = $row_mappings['ldap_attr'];
$row_descriptor = t("server %sid row mapping to ldap attribute %ldap_attr", $tokens);
$tokens['!row_descriptor'] = $row_descriptor;
if (!$row_mappings['direction']) {
$input_name = join('__', [
'sm',
'direction',
$i,
]);
$errors[$input_name] = t('No mapping direction given in !row_descriptor', $tokens);
}
if ($direction == LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER && $row_mappings['user_attr'] == 'user_tokens') {
$input_name = join('__', [
'sm',
'user_attr',
$i,
]);
$errors[$input_name] = t('User tokens not allowed when mapping to Drupal user. Location: !row_descriptor', $tokens);
}
if (!$row_mappings['ldap_attr']) {
$input_name = join('__', [
'sm',
'ldap_attr',
$i,
]);
$errors[$input_name] = t('No ldap attribute given in !row_descriptor', $tokens);
}
if (!$row_mappings['user_attr']) {
$input_name = join('__', [
'sm',
'user_attr',
$i,
]);
$errors[$input_name] = t('No user attribute given in !row_descriptor', $tokens);
}
}
}
return [
$errors,
$warnings,
];
}