Hi,

Thank you for the module. I am able to export the output as a csv with just one issue. The headings for the columns in the csv export have the machine names of the fields instead of the labels. So for example first name is one of the fields in the export and its label is First Name and the machine is field_first_name, the csv export has field_first_name as the heading in the first row. Could you please let me know if there is something I am missing or if there is a way I can achieve that.

Thank you.

Comments

st455 created an issue. See original summary.

d34dman’s picture

Right now to fix your issue you would have to put custom labels in your views ui under Format >> Fields >> settings. Unfortunately it doesn't support spaces. This is probably because in other form of serialization is meant to be used for m2m (machine to machine) communication. CSV is exceptional case, and has to be handled differently, which as far as i know, is not supported yet

hongpong’s picture

Is there a way to hard code in replacement headers for individual columns? It would be nice to force in spaces for a client use case. (their vendor wants spaces in the headers, don't ask me why.)

d34dman’s picture

@HongPong i can understand your predicament. Been through that. A CSV export can have spaces in header. It is supposed to be human readable names. (not saying machine names are not human readable, but still).

How i achieved it is by creating my own Normalizer plugin that extended NormalizerBase, which returned result keyed by "labels contain spaces". Well it is an overkill but fortunately i am a developer who is comfortable with coding.

hongpong’s picture

I'm still getting the hang of plugins and haven't really studied how these pieces fit together in D8 serialization / views world - if some snippet is available in a repo or github gist that would be a thrill.

borisson_’s picture

Status: Active » Needs review
StatusFileSize
new1.74 KB

This make the header row actually use the views settings.

pauloamgomes’s picture

Version: 8.x-1.0-alpha1 » 8.x-1.x-dev
StatusFileSize
new1.89 KB

Minor update on @borisson_ patch, applies ok against 8.x-1.x-dev

plov’s picture

  • grasmash committed 3bfb504 on 8.x-1.x authored by plov
    Issue #2772937 by pauloamgomes, borisson_, plov: Headings in csv have...

grasmash credited grasmash.

grasmash’s picture

Status: Needs review » Fixed
hongpong’s picture

thank you grasmash :)

Status: Fixed » Closed (fixed)

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

c-logemann’s picture

This new feature is breaking the API and causes fatal errors when this module is used e.g. with "Contact Storage Export". There is already an issue for that: #2916034: Fatal error when using CSV Encoder without views context
I just did a quick view into code but I think also the provided tests won't work. Maybe the test system for patches should be enabled to avoid a bug like this in future.