You are here

public function LdapUserConfAdmin::drupalForm in Lightweight Directory Access Protocol (LDAP) 7.2

Same name and namespace in other branches
  1. 8.2 ldap_user/LdapUserConfAdmin.class.php \LdapUserConfAdmin::drupalForm()

Generate admin form for ldapUserConf object.

Return value

array $form as drupal form api form array

File

ldap_user/LdapUserConfAdmin.class.php, line 103

Class

LdapUserConfAdmin

Code

public function drupalForm() {
  if (count($this->drupalAcctProvisionServerOptions) == 0) {
    $message = ldap_servers_no_enabled_servers_msg('configure LDAP User');
    $form['intro'] = [
      '#type' => 'item',
      '#markup' => t('<h1>LDAP User Settings</h1>') . $message,
    ];
    return $form;
  }
  $form['#storage'] = [];
  $form['#theme'] = 'ldap_user_conf_form';
  $form['intro'] = [
    '#type' => 'item',
    '#markup' => t('<h1>LDAP User Settings</h1>'),
  ];
  $form['manual_drupal_account_editing'] = [
    '#type' => 'fieldset',
    '#title' => t('Manual Drupal Account Creation and Updates'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  ];
  $form['manual_drupal_account_editing']['manualAccountConflict'] = [
    '#type' => 'radios',
    '#options' => $this->manualAccountConflictOptions,
    '#title' => t('How to resolve LDAP conflicts with manually  created Drupal accounts.'),
    '#description' => t('This applies only to accounts created manually through admin/people/create
        for which an LDAP entry can be found on the LDAP server selected in "LDAP Servers Providing Provisioning Data"'),
    '#default_value' => $this->manualAccountConflict,
  ];
  $form['basic_to_drupal'] = [
    '#type' => 'fieldset',
    '#title' => t('Basic Provisioning to Drupal Account Settings'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  ];
  $default_value = $this->drupalAcctProvisionServer ? $this->drupalAcctProvisionServer : 'none';
  $form['basic_to_drupal']['drupalAcctProvisionServer'] = [
    '#type' => 'radios',
    '#title' => t('LDAP Servers Providing Provisioning Data'),
    '#required' => 1,
    '#default_value' => $default_value,
    '#options' => $this->drupalAcctProvisionServerOptions,
    '#description' => $this->drupalAcctProvisionServerDescription,
    '#states' => [
      'enabled' => [
        ':input[name=drupalAcctProvisionTriggers]' => [
          'value' => LDAP_USER_DRUPAL_USER_PROV_ON_AUTHENTICATE,
        ],
      ],
    ],
  ];
  $form['basic_to_drupal']['drupalAcctProvisionTriggers'] = [
    '#type' => 'checkboxes',
    '#title' => t('Drupal Account Provisioning Events'),
    '#required' => FALSE,
    '#default_value' => $this->drupalAcctProvisionTriggers,
    '#options' => $this->drupalAccountProvisionEventsOptions,
    '#description' => $this->drupalAccountProvisionEventsDescription,
  ];
  $form['basic_to_drupal']['disableAdminPasswordField'] = [
    '#type' => 'checkbox',
    '#title' => t('Disable the password fields at /admin/create/people since the password is going to be randomly generated anyway. This is useful if you are synching data to Drupal from LDAP, and not bringing the user password from LDAP.'),
    '#default_value' => $this->disableAdminPasswordField,
  ];
  $form['basic_to_drupal']['userConflictResolve'] = [
    '#type' => 'radios',
    '#title' => t('Existing Drupal User Account Conflict'),
    '#required' => 1,
    '#default_value' => $this->userConflictResolve,
    '#options' => $this->userConflictOptions,
    '#description' => t($this->userConflictResolveDescription),
  ];
  $form['basic_to_drupal']['accountsWithSameEmail'] = [
    '#type' => 'radios',
    '#title' => t('Existing Account with Same Email Address'),
    '#default_value' => $this->accountsWithSameEmail,
    '#options' => $this->accountsWithSameEmailOptions,
    '#description' => t($this->accountsWithSameEmailDescription),
    '#disabled' => module_exists('sharedemail') === FALSE,
  ];
  $form['basic_to_drupal']['acctCreation'] = [
    '#type' => 'radios',
    '#title' => t('Application of Drupal Account settings to LDAP Authenticated Users'),
    '#required' => 1,
    '#default_value' => $this->acctCreation,
    '#options' => $this->acctCreationOptions,
    '#description' => t($this->acctCreationDescription),
  ];
  $account_options = [];
  $account_options['ldap_user_orphan_do_not_check'] = t('Do not check for orphaned Drupal accounts.');
  $account_options['ldap_user_orphan_email'] = t('Perform no action, but email list of orphaned accounts. (All the other options will send email summaries also.)');
  foreach (user_cancel_methods() as $option_name => $option) {
    $account_options[$option_name] = $option['#title'];
  }

  // @todo these 2 options are removed until this feature is better tested in
  // actual production environments; it has potentially disastrous effects
  unset($account_options['user_cancel_reassign']);
  unset($account_options['user_cancel_delete']);
  $form['basic_to_drupal']['orphanedDrupalAcctBehavior'] = [
    '#type' => 'radios',
    '#title' => t('Action to perform on Drupal account that no longer have a
        corresponding LDAP entry'),
    '#required' => 0,
    '#default_value' => $this->orphanedDrupalAcctBehavior,
    '#options' => $account_options,
    '#description' => t($this->orphanedDrupalAcctBehaviorDescription),
  ];
  $form['basic_to_drupal']['orphanedCheckQty'] = [
    '#type' => 'textfield',
    '#size' => 10,
    '#title' => t('Number of users to check each cron run.'),
    '#description' => t(''),
    '#default_value' => $this->orphanedCheckQty,
    '#required' => FALSE,
  ];
  $form['basic_to_ldap'] = [
    '#type' => 'fieldset',
    '#title' => t('Basic Provisioning to LDAP Settings'),
    '#collapsible' => TRUE,
    '#collapsed' => !$this->ldapEntryProvisionServer,
  ];
  $default_value = $this->ldapEntryProvisionServer ? $this->ldapEntryProvisionServer : 'none';
  $form['basic_to_ldap']['ldapEntryProvisionServer'] = [
    '#type' => 'radios',
    '#title' => t('LDAP Servers to Provision LDAP Entries on'),
    '#required' => 1,
    '#default_value' => $default_value,
    '#options' => $this->ldapEntryProvisionServerOptions,
    '#description' => $this->ldapEntryProvisionServerDescription,
  ];
  $form['basic_to_ldap']['ldapEntryProvisionTriggers'] = [
    '#type' => 'checkboxes',
    '#title' => t('LDAP Entry Provisioning Events'),
    '#required' => FALSE,
    '#default_value' => $this->ldapEntryProvisionTriggers,
    '#options' => $this->ldapEntryProvisionTriggersOptions,
    '#description' => $this->ldapEntryProvisionTriggersDescription,
  ];
  $form['basic_to_drupal']['server_mapping_preamble'] = [
    '#type' => 'markup',
    '#markup' => t('
The relationship between a Drupal user and an LDAP entry is defined within the LDAP server configurations.


The mappings below are for user fields, properties, and profile2 data that are not automatically mapped elsewhere.
Mappings such as username or email address that are configured elsewhere are shown at the top for clarity.
When more than one ldap server is enabled for provisioning data (or simply more than one configuration for the same ldap server),
mappings need to be setup for each server.  If no tables are listed below, you have not enabled any provisioning servers at
the top of this form.
'),
  ];
  foreach ([
    LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER,
    LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY,
  ] as $direction) {
    $sid = $this->provisionSidFromDirection[$direction];
    $ldap_server = $sid ? ldap_servers_get_servers($sid, NULL, TRUE) : FALSE;
    $ldap_server_selected = (bool) $ldap_server;
    if ($direction == LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER) {
      $parent_fieldset = 'basic_to_drupal';
      $description = t('Provisioning from LDAP to Drupal Mappings:');
    }
    elseif ($direction == LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY) {
      $parent_fieldset = 'basic_to_ldap';
      $description = t('Provisioning from Drupal to LDAP Mappings:');
    }
    $form[$parent_fieldset]['mappings__' . $direction] = [
      '#type' => 'fieldset',
      '#title' => $description,
      '#collapsible' => TRUE,
      '#collapsed' => FALSE,
      '#description' => '',
      'table__' . $direction => [
        '#type' => 'markup',
        '#markup' => '[replace_with_table__' . $direction . ']',
      ],
    ];
    $password_notes = '<h3>' . t('Password Tokens') . '</h3><ul>' . '<li>' . t('Pwd: Random -- Uses a random Drupal generated password') . '</li>' . '<li>' . t('Pwd: User or Random -- Uses password supplied on user forms.
  If none available uses random password.') . '</li></ul>' . '<h3>' . t('Password Concerns') . '</h3>' . '<ul>' . '<li>' . t('Provisioning passwords to LDAP means passwords must meet the LDAP\'s
password requirements.  Password Policy module can be used to add requirements.') . '</li>' . '<li>' . t('Some LDAPs require a user to reset their password if it has been changed
by someone other that user.  Consider this when provisioning LDAP passwords.') . '</li>' . '</ul></p>';
    $source_drupal_token_notes = <<<EOT
<p>Examples in form: Source Drupal User token => Target LDAP Token (notes)</p>
<ul>
<li>Source Drupal User token => Target LDAP Token</li>
<li>cn=[property.name],ou=test,dc=ad,dc=mycollege,dc=edu => [dn] (example of token and constants)</li>
<li>top => [objectclass:0] (example of constants mapped to multivalued attribute)</li>
<li>person => [objectclass:1] (example of constants mapped to multivalued attribute)</li>
<li>organizationalPerson => [objectclass:2] (example of constants mapped to multivalued attribute)</li>
<li>user => [objectclass:3] (example of constants mapped to multivalued attribute)</li>
<li>Drupal Provisioned LDAP Account => [description] (example of constant)</li>
<li>[field.field_lname] => [sn]</li>

</ul>
EOT;

    // Add some password notes.
    if ($direction == LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY) {
      $form[$parent_fieldset]['password_notes'] = [
        '#type' => 'fieldset',
        '#title' => t('Password Notes'),
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
        'directions' => [
          '#type' => 'markup',
          '#markup' => $password_notes,
        ],
      ];
      $form[$parent_fieldset]['source_drupal_token_notes'] = [
        '#type' => 'fieldset',
        '#title' => t('Source Drupal User Tokens and Corresponding Target LDAP Tokens'),
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
        'directions' => [
          '#type' => 'markup',
          '#markup' => $source_drupal_token_notes,
        ],
      ];
    }
    $this
      ->addServerMappingFields($form, $direction);
  }
  foreach ([
    'orphanedCheckQty',
    'orphanedDrupalAcctBehavior',
    'acctCreation',
    'userConflictResolve',
    'accountsWithSameEmail',
    'drupalAcctProvisionTriggers',
    'mappings__' . LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER,
  ] as $input_name) {
    $form['basic_to_drupal'][$input_name]['#states']['invisible'] = [
      ':input[name=drupalAcctProvisionServer]' => [
        'value' => 'none',
      ],
    ];
  }
  foreach ([
    'ldapEntryProvisionTriggers',
    'password_notes',
    'source_drupal_token_notes',
    'mappings__' . LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY,
  ] as $input_name) {
    $form['basic_to_ldap'][$input_name]['#states']['invisible'] = [
      ':input[name=ldapEntryProvisionServer]' => [
        'value' => 'none',
      ],
    ];
  }
  $form['submit'] = [
    '#type' => 'submit',
    '#value' => 'Save',
  ];
  return $form;
}