You are here

public function MigrateSimpleFieldHandler::prepare in Migrate 7.2

Same name and namespace in other branches
  1. 6.2 plugins/destinations/fields.inc \MigrateSimpleFieldHandler::prepare()

File

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

Class

MigrateSimpleFieldHandler
Base class for creating field handlers for fields with a single value.

Code

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

  // Let the derived class skip empty values.
  if ($this->skipEmpty) {
    $values = array_filter($values, array(
      $this,
      'notNull',
    ));
  }

  // Setup the Field API array for saving.
  $delta = 0;
  foreach ($values as $value) {
    if (is_array($language)) {
      $current_language = $language[$delta];
    }
    else {
      $current_language = $language;
    }
    $return[$current_language][] = array(
      $this->fieldValueKey => $value,
    );
    $delta++;
  }
  return isset($return) ? $return : NULL;
}