You are here

class MigrateCckPhoneHandler in Migrate Extras 7.2

Same name and namespace in other branches
  1. 6.2 cck_phone.inc \MigrateCckPhoneHandler

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

Subfields are used to specify all the other values: 'number' - The actual phone number. 'extension' - The extension.

// The country should be passed in as the primary value.
$this
  ->addFieldMapping('field_user_phone', 'profile_country');
$this
  ->addFieldMapping('field_user_phone:number', 'profile_number');
$this
  ->addFieldMapping('field_user_phone:extension', 'profile_extension');

Hierarchy

Expanded class hierarchy of MigrateCckPhoneHandler

1 string reference to 'MigrateCckPhoneHandler'
migrate_extras_migrate_api in ./migrate_extras.migrate.inc

File

./cck_phone.inc, line 18

View source
class MigrateCckPhoneHandler extends MigrateFieldHandler {
  public function __construct() {
    $this
      ->registerTypes(array(
      'phone_number',
    ));
  }
  public function fields($type) {
    return array(
      'number' => t('Subfield: The phone number itself'),
      'extension' => t('Extension: An optional extension'),
    );
  }
  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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MigrateCckPhoneHandler::fields public function
MigrateCckPhoneHandler::prepare public function
MigrateCckPhoneHandler::__construct public function Overrides MigrateHandler::__construct
MigrateFieldHandler::getFieldLanguage function Determine the language of the field.
MigrateHandler::$dependencies protected property List of other handler classes which should be invoked before the current one.
MigrateHandler::$typesHandled protected property List of "types" handled by this handler. Depending on the kind of handler, these may be destination types, field types, etc.
MigrateHandler::getDependencies public function
MigrateHandler::getTypesHandled public function
MigrateHandler::handlesType public function Does this handler handle the given type? 1
MigrateHandler::registerTypes protected function Register a list of types handled by this class