diff --git a/includes/webform.report.inc b/includes/webform.report.inc index 4b85b42..abf8e6d 100644 --- a/includes/webform.report.inc +++ b/includes/webform.report.inc @@ -733,6 +733,9 @@ $header[0] = array_merge($header[0], (array) $component_header[0]); $header[1] = array_merge($header[1], (array) $component_header[1]); $header[2] = array_merge($header[2], (array) $component_header[2]); + + // Allow modules to modify the CSV header. + drupal_alter('webform_csv_header', $component_header, $component); } } } @@ -785,6 +788,10 @@ $raw_data = isset($submission->data[$cid]['value']) ? $submission->data[$cid]['value'] : NULL; if (webform_component_feature($component['type'], 'csv')) { $data = webform_component_invoke($component['type'], 'csv_data', $component, $options, $raw_data); + + // Allow modules to modify the CSV data. + drupal_alter('webform_csv_data', $data, $component, $submission); + if (is_array($data)) { $row = array_merge($row, array_values($data)); } diff --git a/webform.api.php b/webform.api.php index 3eaba85..d54d4a3 100644 --- a/webform.api.php +++ b/webform.api.php @@ -302,6 +302,28 @@ } /** + * Alter a Webform submission's header when exported. + */ +function hook_webform_csv_header_alter(&$header, $component) { + // Use the machine name for component headers, but only for the webform + // with node 5 and components that are text fields. + if ($component['nid'] == 5 && $component['type'] == 'textfield') { + $header[2] = $component['form_key']; + } +} + +/** + * Alter a Webform submission's data when exported. + */ +function hook_webform_csv_data_alter(&$data, $component, $submission) { + // If a value of a field was left blank, use the value from another + // field. + if ($component['cid'] == 1 && empty($data)) { + $data = $submission->data[2]['value'][0]; + } +} + +/** * Define components to Webform. * * @return