-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmobile_number.migrate.inc
57 lines (52 loc) · 1.42 KB
/
mobile_number.migrate.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
/**
* @file
* Integration with Migrate.
*/
/**
* Implements hook_migrate_api().
*/
function mobile_number_migrate_api() {
$api = array(
'api' => 2,
'field handlers' => array('MigrateMobileNumberFieldHandler'),
);
return $api;
}
/**
* Migration class for migrating field content to mobile_number fields.
*/
class MigrateMobileNumberFieldHandler extends MigrateFieldHandler {
/**
* {@inheritdoc}
*/
public function __construct() {
$this->registerTypes(array('mobile_number'));
}
/**
* {@inheritdoc}
*/
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) {
try {
$mobile_number = new MobileNumber($value);
$return[$language][$delta]['value'] = $mobile_number->callableNumber;
$return[$language][$delta]['country'] = $mobile_number->country;
$return[$language][$delta]['local_number'] = $mobile_number->localNumber;
$return[$language][$delta]['verified'] = 0;
$delta++;
}
catch (Exception $e) {
}
}
return isset($return) ? $return : NULL;
}
}