You are here

public function MigrateCckPhoneHandler::prepare in Migrate Extras 7.2

Same name and namespace in other branches
  1. 6.2 cck_phone.inc \MigrateCckPhoneHandler::prepare()

File

./cck_phone.inc, line 30

Class

MigrateCckPhoneHandler
Primary value passed to this field must be the two letter ISO country code of the phone number.

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);

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