diff --git a/includes/media.pages.inc b/includes/media.pages.inc index 6fd75a3..08bd8da 100644 --- a/includes/media.pages.inc +++ b/includes/media.pages.inc @@ -100,10 +100,12 @@ function media_add_upload($form, &$form_state, $params = array()) { $form['#validators'] = $validators; $form['upload'] = array( - '#type' => 'file', + '#type' => 'managed_file', '#title' => t('Upload a new file'), '#description' => theme('file_upload_help', array('description' => '', 'upload_validators' => $validators)), '#upload_validators' => $validators, + '#process' => array('file_managed_file_process','media_add_upload_upload_process'), + '#progress_indicator' => 'bar', ); $form['actions'] = array('#type' => 'actions'); @@ -116,6 +118,26 @@ function media_add_upload($form, &$form_state, $params = array()) { } /** + * Processor to prepare the managed_file element for use with the media browser + * upload tab. + * + * @param $element The upload form element + * @param $form_state + * @param $form + */ +function media_add_upload_upload_process($element, &$form_state, &$form) { + dpm($element['upload_button']); + dpm($form['actions']['submit']); + + // Pin upload button behaviour to submit button + $form['actions']['submit']['#ajax'] = $element['upload_button']['#ajax']; + $form['actions']['submit']['#limit_validation_errors'] = $element['upload_button']['#limit_validation_errors']; + $element['upload_button']['#access'] = FALSE; + + return $element; +} + +/** * Validate the generic file upload with the global media settings. */ function media_add_upload_validate($form, &$form_state) {