1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* On behalf implementation of Feeds mapping API for number.module.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Implements hook_feeds_processor_targets().
|
10
|
*/
|
11
|
function number_feeds_processor_targets($entity_type, $bundle_name) {
|
12
|
$targets = array();
|
13
|
|
14
|
$numeric_types = array(
|
15
|
'number_integer',
|
16
|
'number_decimal',
|
17
|
'number_float',
|
18
|
);
|
19
|
foreach (field_info_instances($entity_type, $bundle_name) as $name => $instance) {
|
20
|
$info = field_info_field($name);
|
21
|
|
22
|
if (in_array($info['type'], $numeric_types)) {
|
23
|
$targets[$name] = array(
|
24
|
'name' => check_plain($instance['label']),
|
25
|
'callback' => 'number_feeds_set_target',
|
26
|
'description' => t('The @label field of the entity.', array('@label' => $instance['label'])),
|
27
|
);
|
28
|
}
|
29
|
}
|
30
|
|
31
|
return $targets;
|
32
|
}
|
33
|
|
34
|
/**
|
35
|
* Callback for mapping number fields.
|
36
|
*/
|
37
|
function number_feeds_set_target(FeedsSource $source, $entity, $target, array $values, array $mapping) {
|
38
|
$language = $mapping['language'];
|
39
|
|
40
|
// Iterate over all values.
|
41
|
$field = isset($entity->$target) ? $entity->$target : array($language => array());
|
42
|
|
43
|
foreach ($values as $value) {
|
44
|
|
45
|
if (is_object($value) && ($value instanceof FeedsElement)) {
|
46
|
$value = $value->getValue();
|
47
|
}
|
48
|
|
49
|
if (is_numeric($value)) {
|
50
|
$field[$language][] = array('value' => $value);
|
51
|
}
|
52
|
}
|
53
|
|
54
|
$entity->$target = $field;
|
55
|
}
|