public function MigrateLocationFieldHandler::prepare in Location 7.3
File
- ./
location.migrate.inc, line 87 - Migrate integration.
Class
Code
public function prepare($entity, array $field_info, array $instance, array $values) {
$migration = Migration::currentMigration();
$destination = $migration
->getDestination();
$arguments = array();
if (isset($values['arguments'])) {
$arguments = $values['arguments'];
unset($values['arguments']);
}
$language = $this
->getFieldLanguage($entity, $field_info, $arguments);
$return = array(
$language => array(),
);
foreach ($values as $delta => $value) {
// Handle potentially multiple arguments.
$instance_arguments = array();
foreach ($arguments as $key => $argument) {
// For a scalar argument, pass it directly.
if (!is_array($argument)) {
if ($delta == 0) {
$instance_arguments[$key] = $argument;
}
}
elseif (isset($argument[$delta])) {
$instance_arguments[$key] = $argument[$delta];
}
}
if (isset($instance_arguments['country'])) {
$instance_arguments['country'] = strtolower($instance_arguments['country']);
}
// Ensure we have at least one location field besides 'is_primary' before saving.
if (!empty($instance_arguments)) {
$instance_arguments['is_primary'] = $delta == 0;
$instance_arguments['inhibit_geocode'] = TRUE;
// Only save the location if saved successfully.
if ($lid = location_save($instance_arguments)) {
$return[$language][$delta] = array_merge(array(
'lid' => $lid,
), $instance_arguments);
}
}
}
return $return;
}