You are here

function _webform_submission_display_file in Webform 6.2

Same name and namespace in other branches
  1. 5.2 components/file.inc \_webform_submission_display_file()
  2. 5 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.

$enabled: If enabled, the value may be changed. Otherwise it will set to readonly.

Return value

Textual output formatted for human reading.

File

components/file.inc, line 416
Webform module file component.

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['#attributes']['readonly'] = 'readonly';
    $form_item['#default_value'] = empty($filedata['filepath']) ? $filedata['error'] : $filedata['filepath'];
  }
  if (!empty($filedata['filename'])) {
    $form_item['#suffix'] = ' <a href="' . webform_file_url($filedata['filepath']) . '">Download ' . webform_file_name($filedata['filepath']) . '</a>' . $form_item['#suffix'];
    if ($enabled) {
      $form_item['#description'] = t('Uploading a new file will replace the current file.');
      $form_item['existing'] = array(
        '#type' => 'value',
        '#value' => $filedata,
      );
    }
  }
  return $form_item;
}