public function MigrateNameHandler::prepare in Name Field 7
Implements MigrateFieldHandler::prepare().
File
- ./
name.migrate.inc, line 66 - Support for migration into Name fields.
Class
- MigrateNameHandler
- Allows using Name fields as Migrate destinations.
Code
public function prepare($entity, array $field_info, array $instance, array $values) {
// Get arguments, if any.
$arguments = array();
if (isset($values['arguments'])) {
$arguments = array_filter($values['arguments']);
unset($values['arguments']);
}
// Get language.
$language = $this
->getFieldLanguage($entity, $field_info, $arguments);
// Get name-specific field settings.
$components = array_filter($field_info['settings']['components']);
// Setup the standard Field API array for saving.
$delta = 0;
foreach ($values as $value) {
// Handle multivalue arguments (especially for subfields).
$delta_arguments = array();
foreach ($arguments as $name => $argument) {
if (is_array($argument) && isset($argument[$delta])) {
$delta_arguments[$name] = $argument[$delta];
}
else {
$delta_arguments[$name] = $argument;
}
}
$item = array(
$this->primaryColumn => $value,
) + array_intersect_key($delta_arguments, $field_info['columns']);
$item = array_intersect_key($item, $components);
if (array_filter($item)) {
$return[$language][] = $item;
}
$delta++;
}
return isset($return[$language]) ? $return : NULL;
}