Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
hook_webform_component_display_alter is great for modifying data when displaying submitted webform results. It would be useful to have a similar hook for exported data.
Comment | File | Size | Author |
---|---|---|---|
#20 | Untitled.jpg | 149.59 KB | gourav.yadav |
#14 | add_export_hooks_d7-1533408-14.patch | 1.98 KB | quicksketch |
#13 | webform-allow-modules-to-alter.patch | 1.24 KB | rahulbile |
#12 | webform-allow-modules-to-alter.patch | 1.25 KB | rahulbile |
#8 | add_export_hooks_d7-1533408-6.patch | 2.4 KB | rlhawk |
Comments
Comment #1
rlhawkThe attached patch adds two hooks: one to alter the CSV header and one to alter the CSV data.
Comment #2
rlhawkExamples of how this could be implemented:
Comment #3
rlhawkOr within a module like Webform Localization to allow exported data to be translated. For instance:
Comment #4
quicksketchSounds like a great idea to me. I'll review this when I have a chance.
Comment #5
rlhawkThanks, quicksketch!
Comment #6
quicksketchIf you can also include documentation in webform.api.php for these new hooks, that would be great and move this along faster.
Comment #7
rlhawkOf course. Will do.
Comment #8
rlhawkHere's a new patch that includes documentation in webform.api.php for the two export hooks. I also added $submission as a parameter to the data hook, so that fields can be altered based on other fields in the submission.
Here's the example I used in the API file:
Comment #9
rlhawkThe API examples had some dumb errors, which I've fixed. Replacement patch attached.
Comment #10
tim.plunkettThis works great and the documentation is there. Is 7.x-3.x getting new features still, this would be nice to have.
Comment #11
pfournier CreditAttribution: pfournier commentedWorks for me!
Comment #12
rahulbile CreditAttribution: rahulbile commentedI wanted to remove and adjust the first two headers values also, so have modified patch a bit, if someone wants to do the same, can use this.
Comment #13
rahulbile CreditAttribution: rahulbile commentedWrong patch attached above. correct patch for changing first two headers values headers if needed.
Comment #14
quicksketchThanks guys, I moved the location of the drupal_alter() call as @rahulbile demonstrated, but kept all the documentation from @rlhawk's patch. Although 3.x is not receiving new features in most cases, this minor change doesn't require any changes for 3.x, so I've committed it to all branches 3.x and 4.x.
Comment #16
j_ten_man CreditAttribution: j_ten_man commentedI'm surprised no one has said anything, but you committed the wrong patch. You committed #12, but #13 is what you should have committed.
Comment #17
DanChadwick CreditAttribution: DanChadwick commentedI don't think so. This has been revised in the 7.x-4.x branch. In that branch, the drupal_alter of webform_csv_header and webform_csv_data allow the component's header and data to be altered, not the row's. There are numerous other alters. I haven't compared this to the -3.x branch, but what I see is proper for 4.x and it would appear from #14 that -3.x is consistent.
If you review the branches and believe I am in error, please do re-open and explain. I only looked at this code briefly.
Comment #18
j_ten_man CreditAttribution: j_ten_man commented7.x-3.x branch is correct, but 7.x-3.20 is incorrect. I'm not sure when you made the change to dev portion of this, but that's why I'm seeing the issue. I'll just modify my 7.x-3.20 to match the dev branch.
Comment #19
DanChadwick CreditAttribution: DanChadwick commentedI'd recommend you just use the dev in that case, rather than patching 3.20. Or maybe it's time for another 3.x release.
Comment #20
gourav.yadav CreditAttribution: gourav.yadav commentedhow to alter exported element's #default-value in webform , i need only 4 columns in my csv file but when load a $form ,i can't seen field
default-value where checked or unchecked.
Comment #21
Aaron23 CreditAttribution: Aaron23 commentedHi Team,
I'm using webform_csv_data_alter and webform_csv_header_alter for modifying my csv file. How can i bring the below structure (In table) in my alter function. All my submission data in one column
Header 1 : WEB
Header 2 : campaign
Header 3 : First Name: Aaron, Second name: Solomon, DOB: 23-10-1991
Thanks,
Aaron