You are here

function getlocations_feeds_set_target in Get Locations 7.2

Same name and namespace in other branches
  1. 7 modules/getlocations_feeds/getlocations_feeds.module \getlocations_feeds_set_target()

Parameters

$source: Field mapper source settings.

$entity: Either a user or node object dpending on where this is called

$target: When targeting sub arrays the '][' is used to drill down. Note that this implementation is lazy ... we assume just depth=2

$value:

Return value

object

1 string reference to 'getlocations_feeds_set_target'
_getlocations_feeds_fill_targets in modules/getlocations_feeds/getlocations_feeds.module
Helper function to add target fields

File

modules/getlocations_feeds/getlocations_feeds.module, line 106
getlocations_feeds.module @author Bob Hutchinson http://drupal.org/user/52366 @copyright GNU GPL

Code

function getlocations_feeds_set_target($source, $entity, $target, $value) {
  if (empty($value)) {
    $value = '';
  }
  if (!is_array($value)) {
    $value = array(
      $value,
    );
  }
  list($field_name, $sub_field) = explode(':', $target);
  if (strpos($sub_field, '][') !== FALSE) {
    list($sub_field, $last_field) = explode('][', $sub_field, 2);
  }
  $language = isset($entity->language) ? $entity->language : LANGUAGE_NONE;
  foreach ($value as $i => $val) {
    $val = trim($val);
    if (isset($last_field)) {
      if (!isset($entity->{$field_name}[$language][$i]['settings'])) {
        $entity->{$field_name}[$language][$i]['settings'] = getlocations_feeds_get_field_info($field_name);
      }
      $entity->{$field_name}[$language][$i][$sub_field][$last_field] = $val;
    }
    else {
      if (!isset($entity->{$field_name}[$language][$i]['settings'])) {
        $entity->{$field_name}[$language][$i]['settings'] = getlocations_feeds_get_field_info($field_name);
      }
      $entity->{$field_name}[$language][$i][$sub_field] = $val;
    }
  }
  return $entity;
}