Problem/Motivation
Sometimes is required to include data regarding the user that sent the webform. The information is in the database but there is no an easy way to do that using webforms. At least is no possible without rewriting 25% of the webform module code.
The proposed solution will not fix the problem by itself, but at least will allow developers to create custom modules to get the information they are intending to get.
Proposed resolution
We have 2 hooks to alter headers and rows individually (one per component), there would be great if we could have two more hooks to alter the whole header and the whole row once it was processed.
Remaining tasks
- Provide the new two hooks.
- Document them.
User interface changes
None.
API changes
Two new hooks:
- hook_webform_csv_headers_alter(&$header, $submission);
- hook_webform_csv_row_alter(&$row, $submission);
Data model changes
None.
Comment | File | Size | Author |
---|---|---|---|
#4 | webform-alter-headers-and-rows-2555703-3.patch | 3.28 KB | dagmar |
Comments
Comment #2
dagmarComment #3
dagmarI will work on this soon.
Comment #4
dagmarHere is the patch. The only thing I'm not 100% sure is if we should pass so many parameters on the second hook, maybe with $node and $options could be enough.
Comment #5
DanChadwick CreditAttribution: DanChadwick commentedHow about using tokens to store this data in hidden component(s)?
Or writing your own hook to alter the content of the hidden component to the data you want?
Or write your own trivial component which includes this data via the existing component hooks? Writing a custom component is quite easy.
I'm thinking that the current API is adequate for this, no?
Comment #6
dagmarHi Dan. yes I know there are current options to add those values, but they require the end user explicitly add N extra components to get the information they need.
One of our clients requested to attach extra information to each webform they download, this hook allow us to add as many columns as we need on every webform created by the end user.
Comment #7
DanChadwick CreditAttribution: DanChadwick commentedMaybe an update script for them to update the existing webforms to add the required components?
It's not that I don't want to accommodate reasonable requests, but rather putting in features that only one client wants out of the hundreds of thousands of webform installations isn't a viable long-term development policy. Each requests adds a little execution time and a little code loading time. If lots of people asked for this, or if it were flat out impossible to accomplish otherwise, I would be more open. As is, I think you have tools to meet the client's needs.
Absent a groundswell of demand for this, I think we should pass on this request. I am sorry. :(
Comment #8
Pls CreditAttribution: Pls as a volunteer commented@dagmar, your patch works perfectly.
Thanks for your work! Just a heads up if someone is checking this out. I think this would be perfect addition to webform module. Couple of drupal_alter's doesn't make much difference for code maintainence. But of course, maintainers have more info here.
Anyway, thanks for this patch. I have altered my XLS export smoothly! ;)
Comment #9
noman_297 CreditAttribution: noman_297 commentedhi @pls i have updated values using hook_webform_results_download_submission_information_data, but the issue with me those values can't update it in export file, do i need to run webform_submission_update($node, $submission) each time I run download xls or csv.
Thanks
Comment #10
Deepesh151086 CreditAttribution: Deepesh151086 at Srijan | A Material+ Company commentedIn Drupal 8 and 9 you can follow my article on medium https://medium.com/@deepesharora.arora1/altering-csv-before-downloading-...