function mobile_number_feeds_set_target in Mobile Number 7
Callback for mapping file fields.
1 string reference to 'mobile_number_feeds_set_target'
File
- ./
mobile_number.feeds.inc, line 57 - Implementation of Feeds mapping API for mobile_number.module.
Code
function mobile_number_feeds_set_target(FeedsSource $source, $entity, $target, array $values, array $mapping) {
$language = $mapping['language'];
list($field_name, $sub_field) = explode(':', $target);
$info = field_info_field($field_name);
// Populate entity.
$field = isset($entity->{$field_name}) ? $entity->{$field_name} : array(
$language => array(),
);
$delta = 0;
foreach ($values as $v) {
if ($info['cardinality'] == $delta) {
break;
}
if (!isset($field[$language][$delta])) {
$field[$language][$delta] = array(
'tfa' => 0,
'verified' => 0,
);
}
$field[$language][$delta][$sub_field] = $v;
switch ($sub_field) {
case 'value':
try {
$mobile_number = new MobileNumber($v);
$field[$language][$delta]['value'] = $mobile_number->callableNumber;
} catch (Exception $e) {
}
break;
case 'country':
if (!empty($field[$language][$delta]['local_number'])) {
try {
$mobile_number = new MobileNumber($field[$language][$delta]['local_number'], $v);
$field[$language][$delta]['value'] = $mobile_number->callableNumber;
} catch (Exception $e) {
}
}
break;
case 'local_number':
if (!empty($field[$language][$delta]['country'])) {
try {
$mobile_number = new MobileNumber($v, $field[$language][$delta]['country']);
$field[$language][$delta]['value'] = $mobile_number->callableNumber;
} catch (Exception $e) {
}
}
break;
}
$delta++;
}
$entity->{$field_name} = $field;
}