class MigratePhoneFieldHandler in Phone 7.2
Same name and namespace in other branches
- 7 phone.migrate.inc \MigratePhoneFieldHandler
Migration class for phone fields.
Hierarchy
- class \MigrateHandler
- class \MigrateFieldHandler
- class \MigratePhoneFieldHandler
- class \MigrateFieldHandler
Expanded class hierarchy of MigratePhoneFieldHandler
1 string reference to 'MigratePhoneFieldHandler'
- phone_migrate_api in ./
phone.migrate.inc - Implements hook_migrate_api().
File
- ./
phone.migrate.inc, line 43 - Support for migrate module.
View source
class MigratePhoneFieldHandler extends MigrateFieldHandler {
/**
* Declares the types of fields used.
*/
public function __construct() {
$this
->registerTypes(array(
'phone',
));
}
/**
* Arguments for a phone field migration.
*
* @param string $countrycode
* The countrycode for a number.
* @param string $numbertype
* The number type for a number.
* @param string $extension
* The extension for a number.
* @param string $language
* Language of the text (defaults to destination language).
*
* @return array
* An array of all the arguments.
*/
static function arguments($countrycode = NULL, $numbertype = NULL, $extension = NULL, $language = NULL) {
$arguments = array();
foreach (array(
'countrycode',
'numbertype',
'extension',
'language',
) as $field) {
if (isset(${$field})) {
$arguments[$field] = ${$field};
}
}
return $arguments;
}
/**
* Implementation of MigrateFieldHandler::fields().
*
* @param string $type
* The field type.
* @param string $parent_field
* Name of the parent field.
* @param Migration $migration
* The migration context for the parent field. We can look at the mappings
* and determine which subfields are relevant.
*
* @return array
* The array of subfields we support.
*/
public function fields($type, $parent_field, $migration = NULL) {
$fields = array(
'countrycode' => t('Subfield: The phone countrycode attribute'),
'numbertype' => t('Subfield: The phone number type'),
'extension' => t('Subfield: The phone extension'),
'language' => t('Subfield: Language for the field'),
);
return $fields;
}
/**
* Converts incoming data into the proper field arrays for Phone fields.
*
* @param object $entity
* The destination entity which will hold the field arrays.
* @param array $field_info
* Metadata for the date field being populated.
* @param array $instance
* Metadata for this instance of the date field being populated.
* @param array $values
* Array of date values to be fielded.
*
* @return array|null
* An array of date fields.
*/
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;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MigrateFieldHandler:: |
function | Determine the language of the field. | ||
MigrateHandler:: |
protected | property | List of other handler classes which should be invoked before the current one. | |
MigrateHandler:: |
protected | property | List of "types" handled by this handler. Depending on the kind of handler, these may be destination types, field types, etc. | |
MigrateHandler:: |
public | function | ||
MigrateHandler:: |
public | function | ||
MigrateHandler:: |
public | function | Does this handler handle the given type? | 1 |
MigrateHandler:: |
protected | function | Register a list of types handled by this class | |
MigratePhoneFieldHandler:: |
static | function | Arguments for a phone field migration. | |
MigratePhoneFieldHandler:: |
public | function | Implementation of MigrateFieldHandler::fields(). | |
MigratePhoneFieldHandler:: |
public | function | Converts incoming data into the proper field arrays for Phone fields. | |
MigratePhoneFieldHandler:: |
public | function |
Declares the types of fields used. Overrides MigrateHandler:: |