Projet

Général

Profil

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

root / drupal7 / sites / all / modules / feeds / tests / modules / feeds_test_field / feeds_test_field.feeds.inc @ ed9a13f1

1
<?php
2

    
3
/**
4
 * @file
5
 * Integration with the Feeds module.
6
 */
7

    
8
/**
9
 * Implements hook_feeds_processor_targets().
10
 */
11
function feeds_test_field_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
    if (in_array($info['type'], array('feeds_test_field'))) {
17
      $targets[$name] = array(
18
        'name' => $instance['label'],
19
        'callback' => 'feeds_test_field_feeds_set_target',
20
        'description' => t('The @label field of the node.', array('@label' => $instance['label'])),
21
      );
22
    }
23
  }
24

    
25
  return $targets;
26
}
27

    
28
/**
29
 * Implements callback_my_module_set_target().
30
 */
31
function feeds_test_field_feeds_set_target(FeedsSource $source, $entity, $target, array $values, array $mapping) {
32
  $language = $mapping['language'];
33

    
34
  // Iterate over all values.
35
  $field = isset($entity->$target) ? $entity->$target : array($language => array());
36

    
37
  foreach ($values as $value) {
38
    $field[$language][] = array('value' => $value);
39
  }
40

    
41
  $entity->$target = $field;
42
}