1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* On behalf implementation of Feeds mapping API for number.module.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
41cc1b08
|
Assos Assos
|
* Implements hook_feeds_processor_targets().
|
10 |
85ad3d82
|
Assos Assos
|
*/
|
11 |
41cc1b08
|
Assos Assos
|
function number_feeds_processor_targets($entity_type, $bundle_name) {
|
12 |
|
|
$targets = array();
|
13 |
|
|
|
14 |
85ad3d82
|
Assos Assos
|
$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 |
41cc1b08
|
Assos Assos
|
|
31 |
|
|
return $targets;
|
32 |
85ad3d82
|
Assos Assos
|
}
|
33 |
|
|
|
34 |
|
|
/**
|
35 |
41cc1b08
|
Assos Assos
|
* Callback for mapping number fields.
|
36 |
85ad3d82
|
Assos Assos
|
*/
|
37 |
a192dc0b
|
Assos Assos
|
function number_feeds_set_target(FeedsSource $source, $entity, $target, array $values, array $mapping) {
|
38 |
|
|
$language = $mapping['language'];
|
39 |
|
|
|
40 |
85ad3d82
|
Assos Assos
|
// Iterate over all values.
|
41 |
a192dc0b
|
Assos Assos
|
$field = isset($entity->$target) ? $entity->$target : array($language => array());
|
42 |
85ad3d82
|
Assos Assos
|
|
43 |
41cc1b08
|
Assos Assos
|
foreach ($values as $value) {
|
44 |
85ad3d82
|
Assos Assos
|
|
45 |
41cc1b08
|
Assos Assos
|
if (is_object($value) && ($value instanceof FeedsElement)) {
|
46 |
|
|
$value = $value->getValue();
|
47 |
85ad3d82
|
Assos Assos
|
}
|
48 |
|
|
|
49 |
41cc1b08
|
Assos Assos
|
if (is_numeric($value)) {
|
50 |
a192dc0b
|
Assos Assos
|
$field[$language][] = array('value' => $value);
|
51 |
85ad3d82
|
Assos Assos
|
}
|
52 |
|
|
}
|
53 |
|
|
|
54 |
|
|
$entity->$target = $field;
|
55 |
|
|
} |