function location_node_import_values_alter in Node import 6
Implementation of hook_node_import_values_alter().
File
- supported/
location/ location.inc, line 87 - Support file for contrib Location module.
Code
function location_node_import_values_alter(&$values, $type, $defaults, $options, $fields, $preview) {
if (($node_type = node_import_type_is_node($type)) !== FALSE) {
$settings = variable_get('location_settings_node_' . $node_type, array());
if (isset($settings['multiple']['max']) && $settings['multiple']['max'] > 0) {
$values['locations'] = array();
$all_location_field_names = array();
foreach (array_keys(location_field_names()) as $fieldname) {
if (isset($settings['form']['fields'][$fieldname]) && $settings['form']['fields'][$fieldname]['collect']) {
$all_location_field_names[] = $fieldname;
}
}
$all_location_field_names[] = 'latitude';
$all_location_field_names[] = 'longitude';
$num_values = 0;
foreach ($all_location_field_names as $fieldname) {
if (!is_array($values['location:' . $fieldname])) {
$values['location:' . $fieldname] = array(
0 => $values['location:' . $fieldname],
);
}
$num_values = max(count($values['location:' . $fieldname]), $num_values);
}
$i = 0;
while ($i < $num_values && $i <= $settings['multiple']['max']) {
$value = array();
foreach ($all_location_field_names as $fieldname) {
if (array_key_exists($i, $values['location:' . $fieldname])) {
$value[$fieldname] = $values['location:' . $fieldname][$i];
}
else {
$value[$fieldname] = $defaults['location:' . $fieldname];
}
}
$value['locpick'] = array(
'user_latitude' => isset($value['latitude']) ? $value['latitude'] : '',
'user_longitude' => isset($value['longitude']) ? $value['longitude'] : '',
);
$value['location_settings'] = $settings;
$values['locations'][] = $value;
$i++;
}
foreach ($all_location_field_names as $fieldname) {
if (isset($values['location:' . $fieldname])) {
unset($values['location:' . $fieldname]);
}
}
}
}
}