public function LdapAuthorizationConsumerDrupalRole::validateAuthorizationMappingTarget in Lightweight Directory Access Protocol (LDAP) 8.2
Same name and namespace in other branches
- 7.2 ldap_authorization/ldap_authorization_drupal_role/LdapAuthorizationConsumerRole.class.php \LdapAuthorizationConsumerDrupalRole::validateAuthorizationMappingTarget()
- 7 ldap_authorization/ldap_authorization_drupal_role/LdapAuthorizationConsumerRole.class.php \LdapAuthorizationConsumerDrupalRole::validateAuthorizationMappingTarget()
* Validate authorization mappings on LDAP Authorization OG Admin form. * *
Parameters
array $mapping single mapping in format generated in normalizeMappings method: * @param array $form_values from authorization configuration form * @param boolean $clear_cache * * @return array of form array($message_type, $message_text) where message type is status, warning, or error * and $message_text is what the user should see. *
Overrides LdapAuthorizationConsumerAbstract::validateAuthorizationMappingTarget
File
- ldap_authorization/
ldap_authorization_drupal_role/ LdapAuthorizationConsumerRole.class.php, line 181
Class
Code
public function validateAuthorizationMappingTarget($mapping, $form_values = NULL, $clear_cache = FALSE) {
$has_form_values = is_array($form_values);
$message_type = NULL;
$message_text = NULL;
$role_name = $mapping['normalized'];
$tokens = array(
'!map_to' => $role_name,
);
$roles_by_name = $this
->existingRolesByRoleName();
$pass = isset($roles_by_name[drupal_strtolower($role_name)]);
if (!$pass) {
$message_text = '"' . t('Drupal role') . ' ' . t('!map_to', $tokens) . '" ' . t('does not map to any existing Drupal roles.');
if ($has_form_values) {
$create_consumers = isset($form_values['synchronization_actions']['create_consumers']) && $form_values['synchronization_actions']['create_consumers'];
}
else {
$create_consumers = $this->consumerConf->createConsumers;
}
if ($create_consumers && $this->allowConsumerObjectCreation) {
$message_type = 'warning';
$message_text .= ' ' . t('"!map_to" will be created when needed. If "!map_to" is not intentional, please fix it.', $tokens);
}
elseif (!$this->allowConsumerObjectCreation) {
$message_type = 'error';
$message_text .= ' ' . t('Since automatic Drupal role creation is not possible with this module, an existing role must be mapped to.');
}
elseif (!$create_consumers) {
$message_type = 'error';
$message_text .= ' ' . t('Since automatic Drupal role creation is disabled, an existing role must be mapped to. Either enable role creation or map to an existing role.');
}
}
return array(
$message_type,
$message_text,
);
}