You are here

public function MigratePhoneFieldHandler::prepare in Phone 7.2

Converts incoming data into the proper field arrays for Phone fields.

Parameters

object $entity: The destination entity which will hold the field arrays.

array $field_info: Metadata for the date field being populated.

array $instance: Metadata for this instance of the date field being populated.

array $values: Array of date values to be fielded.

Return value

array|null An array of date fields.

File

./phone.migrate.inc, line 117
Support for migrate module.

Class

MigratePhoneFieldHandler
Migration class for phone fields.

Code

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

  // Setup the standard Field API array for saving.
  $delta = 0;
  foreach ($values as $number) {
    $item = array();
    if (isset($arguments['countrycode'])) {
      if (is_array($arguments['countrycode'])) {
        $item['countrycode'] = $arguments['countrycode'][$delta];
      }
      else {
        $item['countrycode'] = $arguments['countrycode'];
      }
    }
    if (isset($arguments['numbertype'])) {
      if (is_array($arguments['numbertype'])) {
        $item['numbertype'] = $arguments['numbertype'][$delta];
      }
      else {
        $item['numbertype'] = $arguments['numbertype'];
      }
    }
    if (isset($arguments['extension'])) {
      if (is_array($arguments['extension'])) {
        $item['extension'] = $arguments['extension'][$delta];
      }
      else {
        $item['extension'] = $arguments['extension'];
      }
    }
    $item['number'] = $number;
    if (is_array($language)) {
      $current_language = $language[$delta];
    }
    else {
      $current_language = $language;
    }
    $return[$current_language][] = $item;
    $delta++;
  }
  return isset($return) ? $return : NULL;
}