You are here

public function LdapAuthorizationConsumerConfAdmin::validate in Lightweight Directory Access Protocol (LDAP) 7

Same name and namespace in other branches
  1. 8.2 ldap_authorization/LdapAuthorizationConsumerConfAdmin.class.php \LdapAuthorizationConsumerConfAdmin::validate()
  2. 7.2 ldap_authorization/LdapAuthorizationConsumerConfAdmin.class.php \LdapAuthorizationConsumerConfAdmin::validate()
1 call to LdapAuthorizationConsumerConfAdmin::validate()
LdapAuthorizationConsumerConfAdmin::drupalFormValidate in ldap_authorization/LdapAuthorizationConsumerConfAdmin.class.php

File

ldap_authorization/LdapAuthorizationConsumerConfAdmin.class.php, line 640

Class

LdapAuthorizationConsumerConfAdmin
LDAP Authorization Consumer Configration Admin Class

Code

public function validate($form_values = array()) {
  $errors = array();
  if (!$this->consumerType) {
    $errors['consumer_type'] = t('Consumer type is missing.');
  }
  if ($this->inDatabase && !$this->consumerType) {
    $errors['consumer_type'] = t('Edit or delete called without consumer type in form.');
  }

  // are correct values available for selected mapping approach
  if ($this->deriveFromDn && !trim($this->deriveFromDnAttr)) {
    $errors['derive_from_dn'] = t('DN attribute is missing.');
  }
  if ($this->deriveFromAttr && !count($this->deriveFromAttrAttr)) {
    $errors['derive_from_attr'] = t('Attribute names are missing.');
  }
  if ($this->deriveFromEntry && !count($this->deriveFromEntryEntries)) {
    $errors['derive_from_entry'] = t('Group entries are missing.');
  }
  if ($this->deriveFromEntry && !$this->deriveFromEntryEntriesAttr) {
    $errors['derive_from_entry'] = t('Attribute holding the previous list of values is empty.');
  }
  if ($this->deriveFromEntry && !trim($this->deriveFromEntryMembershipAttr)) {
    $errors['derive_from_entry_attribute'] = t('Membership Attribute is missing.');
  }
  if (count($this->mappings) > 0) {
    foreach ($this->mappings as $mapping_item) {
      list($map_from, $map_to) = $mapping_item;
      list($type, $text) = $this->consumer
        ->validateAuthorizationMappingTarget($map_to, $form_values);
      if ($type == 'error') {
        $errors['mappings'] = $text;
      }
      elseif ($type == 'warning' || $type == 'status') {
        drupal_set_message($text, $type);
      }
    }
  }
  if ($this->useMappingsAsFilter && !count($this->mappings)) {
    $errors['mappings'] = t('Mappings are missing.');
  }
  return $errors;
}