Projet

Général

Profil

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

root / drupal7 / sites / all / modules / email / email.feeds.inc @ 87dbc3bf

1
<?php
2
/**
3
 * @file
4
 * Integration with the Feeds module.
5
 */
6

    
7
/**
8
 * Implements hook_feeds_processor_targets_alter().
9
 *
10
 * @see FeedsNodeProcessor::getMappingTargets().
11
 */
12
function email_feeds_processor_targets_alter(&$targets, $entity_type, $bundle_name) {
13
  foreach (field_info_instances($entity_type, $bundle_name) as $name => $instance) {
14
    $info = field_info_field($name);
15
    if (in_array($info['type'], array('email'))) {
16
      $targets[$name] = array(
17
        'name' => $instance['label'],
18
        'callback' => 'email_feeds_set_target',
19
        'description' => t('The @label field of the node.', array('@label' => $instance['label'])),
20
      );
21
    }
22
  }
23
}
24

    
25
/**
26
 * Callback function for mapping email field.
27
 *
28
 * This function is invoked via hook_feeds_processor_targets_alter().
29
 * Here is where the actual mapping happens.
30
 *
31
 * @param $target
32
 *   the name of the field the user has decided to map to.
33
 * @param $value
34
 *   the value of the feed item element the user has picked as a source.
35
 */
36
function email_feeds_set_target($source, $entity, $target, $value) {
37
  $value = is_array($value) ? $value : array($value);
38

    
39
  $info = field_info_field($target);
40

    
41
  // Iterate over all values.
42
  $i = 0;
43
  $field = isset($entity->$target) ? $entity->$target : array();
44
  foreach ($value as $v) {
45
    if (!is_array($v) && !is_object($v)) {
46
      $field[LANGUAGE_NONE][$i]['email'] = $v;
47
    }
48
    if ($info['cardinality'] == 1) {
49
      break;
50
    }
51
    $i++;
52
  }
53

    
54
  $entity->{$target} = $field;
55
}