You are here

public function ParagraphsMigrateParagraphsFieldHandler::prepare in Paragraphs 7

Overrides MigrateSimpleFieldHandler::prepare

File

migrate/fields/ParagraphsMigrateParagraphsFieldHandler.inc, line 38

Class

ParagraphsMigrateParagraphsFieldHandler
Provides migrate field handler for paragraphs field.

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',
    ));
  }

  // Do not proceed if we got no values.
  if (empty($values)) {
    return NULL;
  }
  $revision_ids = $this
    ->getRevisionIds($values, $arguments);

  // 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,
      'revision_id' => $revision_ids[$delta],
    );
    $delta++;
  }
  return isset($return) ? $return : NULL;
}