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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dagmar created an issue. See original summary.

dagmar’s picture

Issue summary: View changes
dagmar’s picture

Assigned: Unassigned » dagmar

I will work on this soon.

dagmar’s picture

Status: Active » Needs review
FileSize
3.28 KB

Here 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.

DanChadwick’s picture

How 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?

dagmar’s picture

Hi 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.

DanChadwick’s picture

Status: Needs review » Closed (won't fix)

Maybe 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. :(

Pls’s picture

@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! ;)

noman_297’s picture

hi @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

Deepesh151086’s picture

In Drupal 8 and 9 you can follow my article on medium https://medium.com/@deepesharora.arora1/altering-csv-before-downloading-...