function _webform_render_file in Webform 6.3
Same name and namespace in other branches
- 5.2 components/file.inc \_webform_render_file()
- 5 components/file.inc \_webform_render_file()
- 6.2 components/file.inc \_webform_render_file()
- 7.4 components/file.inc \_webform_render_file()
- 7.3 components/file.inc \_webform_render_file()
Implements _webform_render_component().
File
- components/
file.inc, line 269 - Webform module file component.
Code
function _webform_render_file($component, $value = NULL, $filter = TRUE) {
$node = isset($component['nid']) ? node_load($component['nid']) : NULL;
// Normally every file component is given a unique ID based on its key.
if (isset($component['nid'])) {
$node = node_load($component['nid']);
$form_key = implode('_', webform_component_parent_keys($node, $component));
}
else {
$form_key = 'default';
}
$element[$form_key] = array(
'#type' => 'file',
'#title' => $filter ? _webform_filter_xss($component['name']) : $component['name'],
'#title_display' => $component['extra']['title_display'] ? $component['extra']['title_display'] : 'before',
//'#required' => $component['mandatory'], // Drupal core bug with required file uploads.
'#description' => $filter ? _webform_filter_descriptions($component['extra']['description'], $node) : $component['extra']['description'],
'#attributes' => $component['extra']['attributes'],
'#tree' => FALSE,
// file_check_upload assumes a flat $_FILES structure.
'#element_validate' => array(
'_webform_validate_file',
'_webform_required_file',
),
'#pre_render' => array(
'webform_element_title_display',
),
'#translatable' => array(
'title',
'description',
),
'#webform_component' => $component,
);
$element['#webform_required'] = $component['mandatory'];
$element['#webform_form_key'] = $form_key;
$element['#weight'] = $component['weight'];
$element['#theme'] = 'webform_render_file';
$element['#title_display'] = $element[$form_key]['#title_display'];
$element['#theme_wrappers'] = array(
'webform_element_wrapper',
);
$element['#post_render'] = array(
'webform_element_wrapper',
);
// Change the 'width' option to the correct 'size' option.
if ($component['extra']['width'] > 0) {
$element[$form_key]['#size'] = $component['extra']['width'];
}
// Add a hidden element to store the FID for new files.
$element['_fid'] = array(
'#type' => 'hidden',
'#default_value' => '',
);
// Add a hidden element to store the FID for existing files.
$element['_old'] = array(
'#type' => 'hidden',
'#value' => isset($value[0]) ? $value[0] : NULL,
);
return $element;
}