function _webform_render_file in Webform 7.4
Same name and namespace in other branches
- 5.2 components/file.inc \_webform_render_file()
- 5 components/file.inc \_webform_render_file()
- 6.3 components/file.inc \_webform_render_file()
- 6.2 components/file.inc \_webform_render_file()
- 7.3 components/file.inc \_webform_render_file()
Implements _webform_render_component().
File
- components/
file.inc, line 333 - Webform module file component.
Code
function _webform_render_file($component, $value = NULL, $filter = TRUE, $submission = NULL) {
$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',
'#theme' => 'webform_managed_file',
'#title' => $filter ? webform_filter_xss($component['name']) : $component['name'],
'#title_display' => $component['extra']['title_display'] ? $component['extra']['title_display'] : 'before',
'#required' => $component['required'],
'#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/' . ($filter ? drupal_strtolower(webform_replace_tokens($component['extra']['directory'], $node)) : $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',
),
);
if ($filter) {
$element['#description'] = theme('file_upload_help', array(
'description' => $element['#description'],
'upload_validators' => $element['#upload_validators'],
));
}
return $element;
}