Projet

Général

Profil

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

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

1 41cc1b08 Assos Assos
<?php
2
3
/**
4
 * @file
5
 * On behalf implementation of Feeds mapping API for list.module.
6
 */
7
8
/**
9
 * Implements hook_feeds_processor_targets().
10
 */
11
function list_feeds_processor_targets($entity_type, $bundle_name) {
12
  $targets = array();
13
14
  foreach (field_info_instances($entity_type, $bundle_name) as $name => $instance) {
15
    $info = field_info_field($name);
16
17
    switch ($info['type']) {
18
19
      case 'list_integer':
20
      case 'list_float':
21
        $targets[$name] = array(
22
          'name' => check_plain($instance['label']),
23
          'callback' => 'number_feeds_set_target',
24
          'description' => t('The @label field of the entity.', array('@label' => $instance['label'])),
25
        );
26
        break;
27
28
      case 'list_boolean':
29
        $targets[$name] = array(
30
          'name' => check_plain($instance['label']),
31
          'callback' => 'list_feeds_set_boolean_target',
32
          'description' => t('The @label field of the entity.', array('@label' => $instance['label'])),
33
        );
34
        break;
35
36
      case 'list_text':
37
        $targets[$name] = array(
38
          'name' => check_plain($instance['label']),
39
          'callback' => 'text_feeds_set_target',
40
          'description' => t('The @label field of the entity.', array('@label' => $instance['label'])),
41
        );
42
        break;
43
    }
44
  }
45
46
  return $targets;
47
}
48
49
/**
50
 * Callback for setting list_boolean fields.
51
 */
52
function list_feeds_set_boolean_target(FeedsSource $source, $entity, $target, array $values) {
53
  $field = isset($entity->$target) ? $entity->$target : array(LANGUAGE_NONE => array());
54
55
  foreach ($values as $value) {
56
57
    if (is_object($value) && ($value instanceof FeedsElement)) {
58
      $value = $value->getValue();
59
    }
60
61
    $field[LANGUAGE_NONE][] = array('value' => (int) (bool) $value);
62
  }
63
64
  $entity->$target = $field;
65
}