function uif_assign_presave_fields in User Import Framework 7
Prepare core and entity user fields for user_save().
2 calls to uif_assign_presave_fields()
- uif_uif_pre_create in ./
uif.admin.inc - Implements hook_uif_pre_create().
- uif_uif_pre_update in ./
uif.admin.inc - Implements hook_uif_pre_update().
File
- ./
uif.admin.inc, line 759 - Simple, extensible user import from a CSV file.
Code
function uif_assign_presave_fields($account, $user_data, $form_state) {
$value_delimiter = $form_state['storage']['value_delimiter'];
$timestamp_fields = array(
'created',
'access',
'login',
);
$user_fields = array();
foreach ($form_state['storage']['data']['fields'] as $label => $info) {
if (!$info['supported']) {
continue;
}
$parser = uif_isset_or($info['import']['parser']) ? $info['import']['parser'] : 'uif_get_raw_value';
if ($info['type'] == 'core') {
$user_fields[$label] = $parser($account, $info['data'], $user_data[$label]);
}
elseif ($info['type'] == 'entity') {
$field_values = array();
$values = explode($value_delimiter, $user_data[$label]);
$key = uif_isset_or($info['import']['key']) ? $info['import']['key'] : 'value';
foreach ($values as $value) {
$value = trim($value);
if (drupal_strlen($value)) {
$parsed_value = $parser($account, $info['data'], $value);
if (!is_null($parsed_value)) {
$field_values[] = $parsed_value;
}
}
}
for ($delta = 0; $delta < count($field_values); $delta++) {
if ($info['data']['cardinality'] == 1 && $delta > 0) {
break;
}
if (drupal_strlen($field_values[$delta])) {
$user_fields[$label][LANGUAGE_NONE][$delta][$key] = $field_values[$delta];
}
}
}
}
return $user_fields;
}