You are here

function addressfield_phone_feeds_set_target in Address Field Phone 7

Callback for mapping. Here is where the actual mapping happens.

When the callback is invoked, $target contains the name of the field the user has decided to map to and $value contains the value of the feed item element the user has picked as a source.

1 string reference to 'addressfield_phone_feeds_set_target'
addressfield_phone_feeds_processor_targets_alter in ./addressfield_phone.feeds.inc
Implements hook_feeds_processor_targets_alter().

File

./addressfield_phone.feeds.inc, line 48
Feeds integration for Addressfield Phone module.

Code

function addressfield_phone_feeds_set_target($source, $entity, $target, $value) {
  list($field_name, $sub_field) = explode(':', $target, 2);

  // If the field is already set on the given entity, update the existing value
  // array. Otherwise start with a fresh field value array.
  $field = isset($entity->{$field_name}) ? $entity->{$field_name} : array();
  if (isset($field[LANGUAGE_NONE][0]['data'])) {
    $data = unserialize($field[LANGUAGE_NONE][0]['data']);
  }
  $data[$sub_field] = $value;
  $field[LANGUAGE_NONE][0]['data'] = serialize($data);
  $entity->{$field_name} = $field;
}