4 * Integration with the Feeds module.
8 * Implements hook_feeds_processor_targets_alter().
10 * @see FeedsNodeProcessor::getMappingTargets().
12 function civicrm_contact_ref_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('civicrm_contact_ref_contact'))) {
16 $targets[$name] = array(
17 'name' => $instance['label'],
18 'callback' => 'civicrm_contact_ref_feeds_set_target',
19 'description' => t('The @label field of the node.', array('@label' => $instance['label'])),
20 'optional_unique' => TRUE,
27 * Callback function for mapping CiviCRM Contact Ref field.
29 * This function is invoked via hook_feeds_processor_targets_alter().
30 * Here is where the actual mapping happens.
33 * the name of the field the user has decided to map to.
35 * the value of the feed item element the user has picked as a source.
37 function civicrm_contact_ref_feeds_set_target($source, $entity, $target, $value) {
38 $value = is_array($value) ? $value : array($value);
40 $info = field_info_field($target);
42 // Iterate over all values.
44 $field = isset($entity->$target) ? $entity->$target : array();
45 // Allow for multiple mappings to the same target.
47 foreach ($value as $v) {
48 if ($info['cardinality'] == $delta) {
52 if (is_object($v) && ($v instanceof FeedsElement)) {
57 $field['und'][$delta]['contact_id'] = $v;
62 $entity->{$target} = $field;