You are here

public function SimpleLdapUserMap::disableMappedFormFields in Simple LDAP 7

Disable mapped Drupal fields in a form. Used in user profile forms when the server is readonly.

File

simple_ldap_user/SimpleLdapUserMap.class.php, line 93
Class defining the LDAP <-> Drupal user field mappings.

Class

SimpleLdapUserMap
@file Class defining the LDAP <-> Drupal user field mappings.

Code

public function disableMappedFormFields(&$form) {

  // Disable default properties if LDAP server is read-only.
  $form['account']['name']['#disabled'] = $form['account']['mail']['#disabled'] = $form['account']['pass']['#disabled'] = TRUE;

  // Disable mapped fields if LDAP Server is read-only.
  foreach ($this->map as $attribute) {

    // Handle drupal many-to-one mappings.
    foreach ($attribute['drupal'] as $drupal_attribute) {
      if (!($parsed = $this
        ->parseDrupalAttribute($drupal_attribute))) {

        // If we couldn't parse the field name, just continue.
        continue;
      }
      list($is_field, $field_name) = $parsed;
      $parents = array(
        $field_name,
        '#disabled',
      );

      // If this is not a field, it is a property, and therefore lives in
      // $form['account'], so add that to the parents.
      if (!$is_field) {
        array_unshift($parents, 'account');
      }

      // Now set #disabled to TRUE.
      drupal_array_set_nested_value($form, $parents, TRUE);
    }
  }
}