You are here

function _webform_csv_data_addressfield in Addressfield Tokens 7

Format the submitted data of a component for CSV downloading.

The output of this function will be displayed under the "Results" tab then "Download".

Parameters

mixed $component: A Webform component array.

mixed $export_options: An array of options that may configure export of this field.

mixed $value: An array of information containing the submission result, directly correlating to the webform_submitted_data database schema.

Return value

array An array of items to be added to the CSV file. Each value within the array will be another column within the file. This function is called once for every row of data.

File

./addressfield_tokens.components.inc, line 445
Webform Component information for an address field type.

Code

function _webform_csv_data_addressfield($component, $export_options, $value) {
  $address = _addressfield_tokens_expand_value($value);
  if (!empty($component['extra']['csv_separate']) && $component['extra']['csv_separate'] == 1) {

    // Each address component should be in a separate column.
    $return = array();
    $properties = addressfield_tokens_property_names();

    // Ugly alter to let others decide which columns to include.
    // @TODO this should be a config option.
    drupal_alter('addressfield_tokens_download', $properties);
    foreach ($properties as $key => $name) {
      $return[] = isset($address[$key]) ? $address[$key] : '';
    }
    return $return;
  }
  else {

    // The entire address should be displayed in the one column.
    if ($address) {
      return theme('addressfield_formatter__linear', array(
        'address' => $address,
      ));
    }
    return '';
  }
}