I’m working on a project where we’re doing a lot of exporting of (Express) form data as CSVs, and one thing I’ve noticed is that there’s a few hard-coded fields in this export.
publicIdentifier
dateCreated
dateModified
site
authorName
Whilst I can see how these fields would be handy, my client has asked if they can be removed.
The fields appear to be hard coded into the getHeaders function, deep within the CsvWriter used for Express:
I just thought I’d check in case I’ve overlooked something - does anyone know a neat way/trick to remove those, without having to write my own new CSV export function?
I doubt you can do anything without overriding class.
Removing yields at the beginning should do the trick.
I would say, if you want to do it sitewide, the “cleanest” method would be registering custom service provider and overriding core CsvWriter class.
Unfortunately, since this is a private method, you have to copy whole class and not just extend core class and modify one method.
I guess you can also just override dashboard controller and swap CsvWriter with you custom class.
An alternative approach, maybe it could be handled by creating a new end point that internally calls the old end point, gets the CSV, removes the unwanted columns, and passes it through.
Still non-trivial, but maybe easier than messing with the core classes.
@JohntheFish You’ve described what I was thinking of doing instead, as reading and re-exporting a CSV isn’t too tricky. I really just wanted the links within the dashboard to work as is.
It really comes down to how insistant my client is really!
alternatively, if you can modify the single page’s controller (easy to do) you can add a formatter to the writer using addFormatter()
A formatter is any callable that will receive an array of the data so that might be the best place to do that.