You are here

public function LdapQueryAdmin::drupalForm in Lightweight Directory Access Protocol (LDAP) 7

Same name and namespace in other branches
  1. 8.2 ldap_query/LdapQueryAdmin.class.php \LdapQueryAdmin::drupalForm()
  2. 7.2 ldap_query/LdapQueryAdmin.class.php \LdapQueryAdmin::drupalForm()

File

ldap_query/LdapQueryAdmin.class.php, line 161

Class

LdapQueryAdmin

Code

public function drupalForm($op) {
  $form['#prefix'] = t('<p>Setup an LDAP query to be used by other modules such as LDAP Feeds, LDAP Provision, etc.</p>');
  $form['basic'] = array(
    '#type' => 'fieldset',
    '#title' => t('Basic LDAP Query Settings'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['query'] = array(
    '#type' => 'fieldset',
    '#title' => t('Query'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['query_advanced'] = array(
    '#type' => 'fieldset',
    '#title' => t('Advanced Query Settings'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  foreach ($this
    ->fields() as $field_id => $field) {
    $field_group = isset($field['form']['field_group']) ? $field['form']['field_group'] : FALSE;
    if (isset($field['form'])) {
      $form_item = $field['form'];
      $form_item['#default_value'] = $this->{$field['property_name']};
      if ($field_group) {
        $form[$field_group][$field_id] = $form_item;
        unset($form[$field_group][$field_id]['field_group']);

        // sirrelevant to form api
      }
      else {
        $form[$field_id] = $form_item;
      }
    }
  }
  $form['basic']['qid']['#disabled'] = $op == 'edit';
  $servers = ldap_servers_get_servers(NULL, 'enabled');
  if (count($servers) == 0) {
    drupal_set_message(t('No ldap servers configured.  Please configure a server before an ldap query.'), 'error');
  }
  foreach ($servers as $sid => $server) {
    $server_options[$sid] = $server->name;
  }
  $form['basic']['sid']['#options'] = $server_options;
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save Query'),
  );
  $action = $op == 'add' ? 'Add' : 'Update';
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => $action,
    '#weight' => 100,
  );
  return $form;
}