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:

  1. Adding additional form elements using hook_form_webform_results_download_form_alter()
  2. Registering a new submit-handler that is executed before the original one and add additional settings to $form_state['values']['range']
  3. Implement hook_query_webform_download_sids_alter() to manipulate the query according to the additional settings.
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

torotil created an issue. See original summary.

torotil’s picture

Status: Active » Needs review
FileSize
505 bytes

Here is the rather trivial patch implementing this.

torotil’s picture

Here is a small update to make this also work in webform_results_download_form_validate().

ccjjmartin’s picture

Option 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 implementing hook_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:

  1. Apply this patch
  2. Create a custom module or add this hook to an existing module hook_webform_results_download_options_alter(&$options, &$form_state)
  3. Enable the devel module and dpm() $options and $form_state, notice they are passed by reference so $options can be altered
  4. Navigate to a webform download page
  5. Run a download of results with at least one submission
  6. Create your own component or edit an existing components _webform_csv_headers_component($component, $export_options, $value) callback. Do a dpm() of $export_options here and notice your changes in the previous hook have taken effect

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

Liam Morland’s picture

Thanks for the patches.

@torotil, does this do what you need?

torotil’s picture

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

Liam Morland’s picture

Thanks. Can you add a test for this?

@ccjjmartin Does the patch #3 do what you need?

Chris Matthews’s picture

Status: Needs review » Postponed (maintainer needs more info)
Issue tags: +Needs tests

@ccjjmartin Does the patch in #3 do what you need?