function media_update_form_media_edit_alter in Media Update 7.2
Same name and namespace in other branches
- 7 media_update.module \media_update_form_media_edit_alter()
Implements hook_form_FORM_ID_alter().
Adds the original "add" fields for the appropriate media allowing files to be replaced during update.
File
- ./
media_update.module, line 65 - Defines the module media_update.
Code
function media_update_form_media_edit_alter(&$form, &$form_state) {
// Determine the existing schema, and use it to determine appropriate update
// function and params.
$schema = file_uri_scheme($form['preview']['#file']->uri);
$handlers = media_update_get_update_params($schema);
if (isset($handlers['form'])) {
// Call the original add form so that we add the schema-specific fields.
$form = $handlers['form']($form, $form_state);
// If we don't have a defined validate function, add a default validate function.
if (!isset($handlers['validate']) && function_exists($handlers['form'] . '_validate')) {
$form_state['update_validate'] = $handlers['form'] . '_validate';
}
// If we don't have a defined submit function, add a default submit function.
if (!isset($handlers['submit']) && function_exists($handlers['form'] . '_submit')) {
$form_state['update_submit'] = $handlers['form'] . '_submit';
}
// Pull the relevant field and type for "update" recognition.
$form_state['update_field'] = $handlers['field'];
$form_state['update_type'] = $handlers['type'];
unset($form['submit']);
}
// Using the previous function for upload
// NOTE: This funciton saves the file permanently prematurely.
// NOTE: Commenting this out for now, redoing the logic in media_update_submit.
// $form['actions']['submit']['#submit'][] = 'media_add_upload_submit';
$form['actions']['submit']['#validate'][] = 'media_update_validate';
if (!isset($form['actions']['submit']['#submit'])) {
$form['actions']['submit']['#submit'] = array(
'media_edit_submit',
);
}
array_unshift($form['actions']['submit']['#submit'], 'media_update_presubmit');
}