There is an issue I found over at the Views Data Export module forums that I believe may be an Addressfield issue: the inability for Addressfield information to be successfully exported within an otherwise successful Views export. The issue is here: http://drupal.org/node/1437022

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

snufkin’s picture

I think this is a formatter issue. When I set my addressfield to be formatted as address form (as format handler) I get the entries just in one line, concatenated. If i set the formatter to anything else the field will not be included in the export. Maybe its an issue with data export only accepting one line output, or doing the concatenation itself?

caschbre’s picture

Not sure if this is related, but an addressfield cannot be exported / imported with the Features module either. I can provide more details if it sounds related.

bdragon’s picture

Status: Active » Needs review
FileSize
814 bytes

Here's a low impact change that adds some newlines to the output. This seems to do the trick when doing csv exports and such, and shouldn't impact the normal theming since html ignores newlines.

bdragon’s picture

FileSize
574 bytes

Whoops, forgot to strip paths on that patch. Rerolling against an actual checkout....

rszrama’s picture

Title: Addressfield export problem » Add line breaks in the rendered address markup to improve address field data exports
Version: 7.x-1.0-beta2 » 7.x-1.x-dev
Category: bug » feature
Status: Needs review » Needs work
FileSize
937 bytes

There seem to be a few issues being reported here. I installed Views Data Export and was able to:

  1. Export address field data.
  2. Generate the export file via a batch.
  3. Use a custom selection of handlers (i.e. not use the same configuration as the widget.

Either something changed in this module or in Views Data Export to prevent the various bugs reported above. The point above about the Features module does not apply to this particular discussion, but if you can reproduce the inability to export an Address Field and track it down to a problem in this module, I'd be interested to know how that's even possible given our dependence on the same Field API hooks as any other field.

That said, my CSVs do have the address concatenated on a single line as noticed by snufkin, and as bdragon pointed out, that's because the markup generated for the rendered field does not have any line breaks. It's harmless to add them in, but in testing the patch I noticed the unfortunate side effect as it pertains to data export that if you just do something simple like only use the name line plugin, then you end up with a line break after the name even though there are no additional lines.

I've attached my update to bdragon's patch, but I'm not going to commit it just yet. I feel like it might be better to handle this earlier using suffixes in the render array where we can process it to only put them in if necessary.

farmherd’s picture

Does this need to be accomplished within the module itself or would it sit better with a theme function?

I note that addressfieldtokens module includes formatters for exporting an address to one line for use with exports using a comma;

A quick test replacing line 82 of the function theme_addressfield_formatter__linear within addressfield_tokens.theme.inc [ $output = implode(', ', $out) ; ] with $output = implode("\n ", $out) appears to give the functionality desired above. (note the double quotes)

Duplicating and renaming that function with addressfieldtokens would seem to be an appropriate way forward rather than putting the functionality directly into addressfield

This approach also avoids the problem of the superfluous newline created when a field is blank.

dang42’s picture

Any further progress on this?

For my use case, it would be fine to either (a) separate each field into its own column (when exported), or (b) concatenate all the address fields into one column.

Applying the patch in #5 did separate the street address and city fields (though it pushes the city to a 2nd line for some reason...), but it did not separate the state & zip code fields.

ETA:

Nevermind...

I had been trying to export the full "Address" field - removing that & exporting the individual fields (Address - City, Address - State, etc.) works exactly as expected.

catch’s picture

Issue summary: View changes
Status: Needs work » Needs review

Just ran into this and considered the same as #5, then found this issue when searching. I think that patch is actually fine - it's not going to have negative side-effects and making this configurable seems unnecessary.

rooby’s picture

I've run into this too.

Ideally the views field handler would have a field where you can enter a separator, then you could have " " or ", " or "\n" or whatever suited your requirements.

rooby’s picture

The current patch is working for me though.

tonylegrone’s picture

Is there any possibility of rendering each component as a separate field instead of a single field with the whole address? This would give each component it's own column in the data export and potentially making a more usable export in the end.

tonylegrone’s picture

Rerolled #5 to match latest code.

dtamajon’s picture

Patch is working fine to me on export and no side-effects on display.

dtamajon’s picture

Just a small adjust... PHP_EOL should be used instead "\n", to help newline handling based on platform.

leewillis77’s picture

This is a re-roll of the patch in #12 with the modification to change \n to PHP_EOL as suggested in #14.

Works well for us here.

liquidcms’s picture

this worked for me; great help.. thanks.

Anybody’s picture

Works great for me! Further feedback to get this RTBC? :)

leewillis77’s picture

Status: Needs review » Reviewed & tested by the community

I think there are four separate people happy with this patch & approach. RTBC?

bojanz’s picture

Status: Reviewed & tested by the community » Fixed

Committed.

  • bojanz committed 8c794f6 on 7.x-1.x authored by rszrama
    Issue #1493014 by bdragon, leewillis77, tonylegrone, rszrama: Add line...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.