You are here

function _webform_render_file in Webform 7.3

Same name and namespace in other branches
  1. 5.2 components/file.inc \_webform_render_file()
  2. 5 components/file.inc \_webform_render_file()
  3. 6.3 components/file.inc \_webform_render_file()
  4. 6.2 components/file.inc \_webform_render_file()
  5. 7.4 components/file.inc \_webform_render_file()

Implements _webform_render_component().

File

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

Code

function _webform_render_file($component, $value = NULL, $filter = TRUE) {
  $node = isset($component['nid']) ? node_load($component['nid']) : NULL;

  // Cap the upload size according to the PHP limit.
  $max_filesize = parse_size(file_upload_max_size());
  $set_filesize = $component['extra']['filtering']['size'];
  if (!empty($set_filesize) && parse_size($set_filesize) < $max_filesize) {
    $max_filesize = parse_size($set_filesize);
  }
  $element = array(
    '#type' => 'managed_file',
    '#title' => $filter ? _webform_filter_xss($component['name']) : $component['name'],
    '#title_display' => $component['extra']['title_display'] ? $component['extra']['title_display'] : 'before',
    '#required' => $component['mandatory'],
    '#default_value' => isset($value[0]) ? $value[0] : NULL,
    '#attributes' => $component['extra']['attributes'],
    '#upload_validators' => array(
      'file_validate_size' => array(
        $max_filesize,
      ),
      'file_validate_extensions' => array(
        implode(' ', $component['extra']['filtering']['types']),
      ),
    ),
    '#pre_render' => array_merge(element_info_property('managed_file', '#pre_render'), array(
      'webform_file_allow_access',
    )),
    '#upload_location' => $component['extra']['scheme'] . '://webform/' . $component['extra']['directory'],
    '#progress_indicator' => $component['extra']['progress_indicator'],
    '#description' => $filter ? _webform_filter_descriptions($component['extra']['description'], $node) : $component['extra']['description'],
    '#weight' => $component['weight'],
    '#theme_wrappers' => array(
      'webform_element',
    ),
    '#translatable' => array(
      'title',
      'description',
    ),
  );
  return $element;
}