Hello Sorin,

1st of all, thank you for fantastic work on this module : it is a lot more lightweight and easier to use than Feeds (and natively compatible with D7 entities, thank God :)

I know you cannot make your module compatible with every field type on the Drupal planet, but I just wanted to know how I can extrapolate the code from your explanation #9 in issue #1442500 : Import Failing with Taxonomy Filters. I'm trying to apply the same method you used to nest my xml location nodes into multiple fields of the location field., but I'm a little lost about how to make the same function (I'm pretty new to php unfortunately)

Location filed array

Your original code for the date field :

function convert_to_date_field($dt, $format = 'Y-m-d H:i:s') {
  if (is_array($dt)) {
    if (isset($dt[1])) {
      return (object) array(
        'value' => date($format, (int) $dt[0]),
        'value2' => date($format, (int) $dt[1]),
        'date_type' => 'datetime',
        // other ...
      );
    }
    else {
      return (object) array(
        'value' => date($format, (int) $dt[0]),
        'date_type' => 'datetime',
        // other ...
      );
    }
  }
  return (object) array(
    'value' => date($format, (int) $dt),
    'date_type' => 'datetime',
    // other ...
  );
}

Sorry for this "newbie" request, but it might help others to know as well...

CommentFileSizeAuthor
Location_field_array.png13.24 KBoryx

Comments

oryx’s picture

Issue summary: View changes

Added the screen cap in the body

blake.thompson’s picture

Probably a bit late for this, but my method of doing addresses has been to add a custom field for each property (thoroughfare, locality, etc) with the last attribute using the defined field (ex: custom fields _address1, _address2, _city, _state, and put the path for zip in defined field_address) and apply this filter function to all of them. It should apply it directly to the import object. The filter function needs to received the field value as the first parameter and the string for the property the address field needs as the second parameter.

The field would need to be Ingored when empty, since the values are being applied to the import object. Since the function does not return a value this should prevent your custom fields from being attached to the import object.

My functions are also applying a country by default if it doesn't exist. They're also dependent on the address field being named 'field_address' otherwise you'd have to pass a 3rd parameter for the field name and adjust the code to use it.

This code is for 7.x-3.x

    function address_field($field, $property)
    {
        FeedImport::$activeImport->current['field_address'][LANGUAGE_NONE][0][$property] = preg_replace('/\s{2,}/', ' ', trim($field));
        if (!array_key_exists('country', FeedImport::$activeImport->current['field_address'][LANGUAGE_NONE][0])) {
            FeedImport::$activeImport->current['field_address'][LANGUAGE_NONE][0]['country'] = 'US';
        }
    }

Possible 7.x-2.x code, not sure if it will work.

    function address_field($field, $property)
    {
        FeedImport::$current->field_address[LANGUAGE_NONE][0][$property] = preg_replace('/\s{2,}/', ' ', trim($field));
        if (!array_key_exists('country', FeedImport::$current->field_address[LANGUAGE_NONE][0])) {
            FeedImport::$current->field_address[LANGUAGE_NONE][0]['country'] = 'US';
        }
    }
Sorin Sarca’s picture

Status: Active » Closed (outdated)