You are here

public function MigrateDefaultFieldHandler::prepare in Migrate 7.2

Implements MigrateFieldHandler::prepare().

Parameters

$entity:

array $field_info:

array $instance:

array $values:

Return value

null

File

plugins/destinations/fields.inc, line 190
Support for processing entity fields

Class

MigrateDefaultFieldHandler
A fallback field handler to do basic copying of field data.

Code

public function prepare($entity, array $field_info, array $instance, array $values) {
  $arguments = array();
  if (isset($values['arguments'])) {
    $arguments = array_filter($values['arguments']);
    unset($values['arguments']);
  }
  $language = $this
    ->getFieldLanguage($entity, $field_info, $arguments);

  // Get the name of the primary (first) column, which is mapped separately.
  reset($field_info['columns']);
  $primary_column = key($field_info['columns']);

  // 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) && array_key_exists($delta, $argument)) {
        $delta_arguments[$name] = $argument[$delta];
      }
      else {
        $delta_arguments[$name] = $argument;
      }
    }
    $return[$language][$delta] = array(
      $primary_column => $value,
    ) + array_intersect_key($delta_arguments, $field_info['columns']);
    $delta++;
  }
  return isset($return) ? $return : NULL;
}