Projet

Général

Profil

Paste
Télécharger (1,26 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / feeds / mappers / number.inc @ 41cc1b08

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) {
38
  // Iterate over all values.
39
  $field = isset($entity->$target) ? $entity->$target : array('und' => array());
40

    
41
  foreach ($values as $value) {
42

    
43
    if (is_object($value) && ($value instanceof FeedsElement)) {
44
      $value = $value->getValue();
45
    }
46

    
47
    if (is_numeric($value)) {
48
      $field['und'][] = array('value' => $value);
49
    }
50
  }
51

    
52
  $entity->$target = $field;
53
}