You are here

function _webform_submission_display_file in Webform 5

Same name and namespace in other branches
  1. 5.2 components/file.inc \_webform_submission_display_file()
  2. 6.2 components/file.inc \_webform_submission_display_file()

Display the result of a file submission. The output of this function will be displayed under the "results" tab then "submissions".

Parameters

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

$component: An array of information describing the component, directly correlating to the webform_component database schema.

Return value

Textual output formatted for human reading.

File

components/file.inc, line 321

Code

function _webform_submission_display_file($data, $component, $enabled = false) {
  $filedata = unserialize($data['value'][0]);
  $form_item = _webform_render_file($component);
  if (!$enabled) {
    $form_item['#type'] = 'textfield';
    $form_item['#tree'] = TRUE;
    $form_item['#disabled'] = TRUE;
    $form_item['#default_value'] = empty($filedata['filepath']) ? $filedata['error'] : $filedata['filepath'];
  }
  if ($filedata['filename']) {
    $form_item['#suffix'] = ' <a href="' . file_create_url($filedata['filepath']) . '">Download ' . $filedata['filename'] . '</a></div>' . $form_item['#suffix'];
    if ($enabled) {
      $form_item['#description'] = t('Uploading a new file will replace the current file.');
      $form_item['#webform_current_file'] = $filedata;
    }
  }
  return $form_item;
}