In webform_confirm_email we want to extend the results download form with an additional filter.
Currently this is achieved in a rather hacky way by completely replacing the form and all it's submit-handlers.
While browsing through the code I found that it only needs a tiny modification to webform to make it extensible in this way.
Proposed change
In webform_download_sids_query()
use addMetaData()
to make the $range_options
available in hook_query_webform_download_sids_alter()
.
This way new options can be injected by:
- Adding additional form elements using
hook_form_webform_results_download_form_alter()
- Registering a new submit-handler that is executed before the original one and add additional settings to
$form_state['values']['range']
- Implement
hook_query_webform_download_sids_alter()
to manipulate the query according to the additional settings.
Comment | File | Size | Author |
---|---|---|---|
#4 | webform-2869525-download-options-4.patch | 1.42 KB | ccjjmartin |
| |||
#3 | 2869525-3-addMetaData-range_options.patch | 1.14 KB | torotil |
|
Comments
Comment #2
torotil CreditAttribution: torotil at more onion commentedHere is the rather trivial patch implementing this.
Comment #3
torotil CreditAttribution: torotil at more onion commentedHere is a small update to make this also work in
webform_results_download_form_validate()
.Comment #4
ccjjmartin CreditAttribution: ccjjmartin at Four Kitchens commentedOption 2:
Background:
I ran into a similar issue where I needed to alter the download options / create some new options for the webform_matrix_component module. I solved this by adding an alter hook in
webform_results_download_form_submit()
which would allow any module implementinghook_webform_results_download_options_alter()
to change/add download options before they are passed off to components header_webform_csv_headers_component
and data_webform_csv_data_component
hooks.Testing:
hook_webform_results_download_options_alter(&$options, &$form_state)
dpm()
$options
and$form_state
, notice they are passed by reference so$options
can be altered_webform_csv_headers_component($component, $export_options, $value)
callback. Do adpm()
of$export_options
here and notice your changes in the previous hook have taken effectKnown Limitations:
Before considering going with this option please note that the download format will not be able to be changed as it is a separate variable within this function
webform_results_download_form_submit()
.Addressing hurdle in previous solution
The range options will be available in the
hook_webform_results_download_options_alter(&$options, &$form_state)
by altering$options['range']
I have attached a patch with an update to webform.api.php for example useage. Also keep an eye out for related issues updates as I will be relating this to the webform_matrix_component module patch soon.
Comment #5
Liam MorlandThanks for the patches.
@torotil, does this do what you need?
Comment #6
torotil CreditAttribution: torotil at more onion commented@Liam I don’t think so. The latest patch does not allow you to use the range options to alter the query.
You can add all the options you want but if the query-builder doesn’t handle them they are simply ignored. The core of my patch (#3) was to make this data available in
hook_query_*_alter()
. The new patch provides an alternate way to do steps 1 & 2 in my proposed solution (see issue summary) but does not allow for 3.Comment #7
Liam MorlandThanks. Can you add a test for this?
@ccjjmartin Does the patch #3 do what you need?
Comment #8
Chris Matthews CreditAttribution: Chris Matthews as a volunteer commented@ccjjmartin Does the patch in #3 do what you need?