You are here

function user_import_form_field_match in User Import 5

Same name and namespace in other branches
  1. 8 user_import.admin.inc \user_import_form_field_match()
  2. 5.2 user_import.module \user_import_form_field_match()
  3. 6.4 user_import.admin.inc \user_import_form_field_match()
  4. 6.2 user_import.admin.inc \user_import_form_field_match()
  5. 7.3 user_import.admin.inc \user_import_form_field_match()
  6. 7 user_import.admin.inc \user_import_form_field_match()
  7. 7.2 user_import.admin.inc \user_import_form_field_match()
1 call to user_import_form_field_match()
user_import_edit_form in ./user_import.module

File

./user_import.module, line 1056
Import users from a comma separated file (csv).

Code

function user_import_form_field_match(&$form, $import) {
  $collapsed = empty($import['name']) ? FALSE : TRUE;
  $handle = _user_import_file_open($form['filepath']['#value'], $form['filename']['#value']);
  $data_row = _user_import_file_row($form['filename']['#value'], $handle);
  $fieldmatch_description = t("Match columns in CSV file to profile fields, leave as '----' if there is no match.");
  $fieldmatch_description .= '<br /><strong>' . t('Username') . ': </strong>' . t("The Username will be built from CSV columns in the order selected.");
  $fieldmatch_description .= '<br /><strong>' . t('Abbreviate') . ': </strong>' . t("Use the first letter of a field in uppercase for the Username, e.g. 'john' -> 'J'.");
  $fieldmatch_description .= '<br />' . t("If no CSV fields are selected, the Username will be randomly generated.");
  $form['field_match'] = array(
    '#type' => 'fieldset',
    '#title' => t('Field Match'),
    '#description' => $fieldmatch_description,
    '#weight' => -90,
    '#collapsible' => TRUE,
    '#collapsed' => $collapsed,
    '#tree' => TRUE,
  );

  // add default and email address options
  $user_fields[0] = '-------------';
  $additional_user_fields = module_invoke_all('user_import_form_field_match');
  foreach ($additional_user_fields as $type => $type_options) {
    if (is_array($type_options)) {
      foreach ($type_options as $field_id => $label) {
        $user_fields["{$type}-{$field_id}"] = $label;
      }
    }
  }
  asort($user_fields);
  $row = 0;
  $sort = array(
    t('no'),
    1,
    2,
    3,
    4,
  );
  if (empty($data_row)) {
    return;
  }
  foreach ($data_row as $data_cell) {
    $form['field_match'][$row] = array(
      '#tree' => TRUE,
    );
    $form['field_match'][$row]['csv'] = array(
      '#value' => check_plain(drupal_substr($data_cell, 0, 40)),
    );
    $form['field_match'][$row]['field_match'] = array(
      '#type' => 'select',
      '#default_value' => $import['field_match'][$row]['field_match'] ? $import['field_match'][$row]['field_match'] : $user_fields[0],
      '#options' => $user_fields,
    );
    $form['field_match'][$row]['username'] = array(
      '#type' => 'select',
      '#default_value' => $import['field_match'][$row]['username'] ? $import['field_match'][$row]['username'] : $sort[0],
      '#options' => $sort,
    );
    $form['field_match'][$row]['abbreviate'] = array(
      '#type' => 'checkbox',
      '#default_value' => $import['field_match'][$row]['abbreviate'] ? $import['field_match'][$row]['abbreviate'] : NULL,
    );
    $row++;
  }
  return;
}