You are here

private function LdapUserConfAdmin::synchMappingsFromForm in Lightweight Directory Access Protocol (LDAP) 8.2

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

Extract synch mappings array from mapping table in admin form.

Parameters

array $values as $form_state['values'] from drupal form api:

array $storage as $form_state['storage'] from drupal form api:

$values input names in form: 1__sm__configurable__5, 1__sm__remove__5, 1__sm__ldap_attr__5, 1__sm__convert__5, 1__sm__direction__5, 1__sm__user_attr__5, 1__sm__user_tokens__5 1__sm__1__5, 1__sm__2__5, ...where -- first arg is direction, eg 1 or 2 LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER or LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY -- second arg is discarded ('sm') -- third part is field, e.g. user_attr -- fourth is the row in the configuration form, e.g. 5

where additiond data is in $form['#storage'][<direction>]['synch_mapping_fields'][N] $form['#storage']['synch_mapping_fields'][<direction>][N] = array( 'sid' => $sid, 'action' => 'add', );

1 call to LdapUserConfAdmin::synchMappingsFromForm()
LdapUserConfAdmin::populateFromDrupalForm in ldap_user/LdapUserConfAdmin.class.php
populate object with data from form values

File

ldap_user/LdapUserConfAdmin.class.php, line 637

Class

LdapUserConfAdmin

Code

private function synchMappingsFromForm($values, $storage) {
  $mappings = array();
  foreach ($values as $field => $value) {
    $parts = explode('__', $field);

    // since synch mapping fields are in n-tuples, process entire n-tuple at once
    if (count($parts) != 4 || $parts[1] !== 'sm') {
      continue;
    }
    list($direction, $discard, $column_name, $i) = $parts;
    $action = $storage['synch_mapping_fields'][$direction][$i]['action'];
    $row_mappings = array();
    foreach (array(
      'remove',
      'configurable_to_drupal',
      'configurable_to_ldap',
      'convert',
      'ldap_attr',
      'user_attr',
      'user_tokens',
    ) as $column_name) {
      $input_name = join('__', array(
        $direction,
        'sm',
        $column_name,
        $i,
      ));
      $row_mappings[$column_name] = isset($values[$input_name]) ? $values[$input_name] : NULL;
    }
    if ($row_mappings['remove']) {
      continue;
    }
    $key = $direction == LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER ? $row_mappings['user_attr'] : $row_mappings['ldap_attr'];
    if ($row_mappings['configurable_to_drupal'] && $row_mappings['ldap_attr'] && $row_mappings['user_attr']) {
      $mappings[$direction][$key] = array(
        'ldap_attr' => $row_mappings['ldap_attr'],
        'user_attr' => $row_mappings['user_attr'],
        'convert' => $row_mappings['convert'],
        'direction' => $direction,
        'user_tokens' => $row_mappings['user_tokens'],
        'config_module' => 'ldap_user',
        'prov_module' => 'ldap_user',
        'enabled' => 1,
      );
      $synchEvents = $direction == LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER ? $this->provisionsDrupalEvents : $this->provisionsLdapEvents;
      foreach ($synchEvents as $prov_event => $discard) {
        $input_name = join('__', array(
          $direction,
          'sm',
          $prov_event,
          $i,
        ));
        if (isset($values[$input_name]) && $values[$input_name]) {
          $mappings[$direction][$key]['prov_events'][] = $prov_event;
        }
      }
    }
  }
  return $mappings;
}