You are here

public function RangeMigrateFieldHandler::prepare in Range 7

File

migrate/destinations/range.inc, line 63
Contains range field migration handler.

Class

RangeMigrateFieldHandler
Range field migration handler class.

Code

public function prepare($entity, array $field_info, array $instance, array $values) {
  $arguments = isset($values['arguments']) ? $values['arguments'] : array();
  $arguments += array(
    'from' => array(),
    'to' => array(),
  );

  // When a single value is mapped to an argument, Migrate module doesn't wrap
  // it in array.
  foreach (array(
    'from',
    'to',
  ) as $subelement) {
    if (!is_array($arguments[$subelement])) {
      $arguments[$subelement] = array(
        $arguments[$subelement],
      );
    }
  }
  $return = array();
  foreach ($arguments['from'] as $delta => $value) {
    $item = array(
      'from' => $arguments['from'][$delta],
      'to' => isset($arguments['to'][$delta]) ? $arguments['to'][$delta] : NULL,
    );
    if ($this
      ->validate($entity, $field_info, $instance, $item)) {
      $language = $this
        ->getRangeFieldLanguage($entity, $field_info, $arguments, $delta);
      $return[$language][] = $item;
    }
  }
  return !empty($return) ? $return : NULL;
}