Managed File
Categories
Component ID
2664906
Component name
Managed File
Component type
module
Maintenance status
Development status
Component security advisory coverage
covered
Downloads
3549
Component created
Component changed
Component body
Extend default managed_file widget, which is a part of Form API, by a set of useful features. See examples below to be involved.
Usage
These additional options for element with '#type' => 'managed_file' is come with this module:
Add the Browse files link before the file input to use one of available file managers:
// Also could be "ckfinder".
'#widget' => 'imce',
Tired to add an image styles for every managed file field?
// Add an additional "select" element with image styles.
'#styles' => TRUE,
Want a preview of the uploaded file?
// Append a preview of the uploaded file.
'#preview' => TRUE,
Also this module implements an API of the File MD5 module.
Complete example
$form['image'] = [
'#type' => 'managed_file',
'#title' => t('Image'),
// Also could be "ckfinder".
'#widget' => 'imce',
// Add an additional "select" element with image styles. When this is TRUE,
// then return value will be an array with two properties: "fid" and "style"
// instead of usual file ID as a string.
'#styles' => TRUE,
// Append a preview of the uploaded file.
'#preview' => TRUE,
];
Tracking the usage of file
Remember, that to successfully track the file in your Drupal system you have to invoke the managed_file_element_submit() in a submit callback of the form.
Take a look at the module for testing as an example of complete implementation.
