diff --git a/file_entity.pages.inc b/file_entity.pages.inc index bb61c48..d892302 100644 --- a/file_entity.pages.inc +++ b/file_entity.pages.inc @@ -333,10 +333,13 @@ function file_entity_add_upload_submit($form, &$form_state) { // This var is set to TRUE when we are ready to save the file. $save = FALSE; - $trigger = $form_state['triggering_element']['#id']; + + // Form id's can vary depending on how many other forms are displayed, so we + // need to do find the string part of it. e.g submit from edit-submit--2. + list(,$trigger,) = explode('-', $form_state['triggering_element']['#id'], 3); $steps_to_check = array(2, 3); - if ($trigger == 'edit-previous') { + if ($trigger == 'previous') { // If the previous button was hit, // the step checking order should be reversed 3, 2. $steps_to_check = array_reverse($steps_to_check); @@ -344,7 +347,7 @@ function file_entity_add_upload_submit($form, &$form_state) { foreach ($steps_to_check as $step) { // Check if we can skip step 2 and 3. - if (($form['#step'] == $step - 1 && $trigger == 'edit-next') || ($form['#step'] == $step + 1 && $trigger == 'edit-previous')) { + if (($form['#step'] == $step - 1 && $trigger == 'next') || ($form['#step'] == $step + 1 && $trigger == 'previous')) { $file = file_load($form_state['storage']['upload']); if ($step == 2) { // Check if we can skip step 2. @@ -353,12 +356,12 @@ function file_entity_add_upload_submit($form, &$form_state) { $candidates_keys = array_keys($candidates); // There is only one possible filetype for this file. // Skip the second page. - $form['#step'] += ($trigger == 'edit-previous') ? -1 : 1; + $form['#step'] += ($trigger == 'previous') ? -1 : 1; $form_state['storage']['type'] = reset($candidates_keys); } elseif (!$candidates || variable_get('file_entity_file_upload_wizard_skip_file_type', FALSE)) { // Do not assign the file a file type. - $form['#step'] += ($trigger == 'edit-previous') ? -1 : 1; + $form['#step'] += ($trigger == 'previous') ? -1 : 1; $form_state['storage']['type'] = FILE_TYPE_NONE; } } @@ -374,17 +377,17 @@ function file_entity_add_upload_submit($form, &$form_state) { if (!file_entity_file_is_writeable($file)) { // The file is read-only (remote) and must use its provided scheme. - $form['#step'] += ($trigger == 'edit-previous') ? -1 : 1; + $form['#step'] += ($trigger == 'previous') ? -1 : 1; $form_state['storage']['scheme'] = file_uri_scheme($file->uri); } elseif (count($schemes) == 1) { // There is only one possible stream wrapper for this file. // Skip the third page. - $form['#step'] += ($trigger == 'edit-previous') ? -1 : 1; + $form['#step'] += ($trigger == 'previous') ? -1 : 1; $form_state['storage']['scheme'] = key($schemes); } elseif (variable_get('file_entity_file_upload_wizard_skip_scheme', FALSE)) { - $form['#step'] += ($trigger == 'edit-previous') ? -1 : 1; + $form['#step'] += ($trigger == 'previous') ? -1 : 1; // Fallback to the URI scheme specified in the field settings // otherwise use the default file scheme. @@ -400,7 +403,7 @@ function file_entity_add_upload_submit($form, &$form_state) { } // We have the filetype, check if we can skip step 4. - if (($form['#step'] == 3 && $trigger == 'edit-next')) { + if (($form['#step'] == 3 && $trigger == 'next')) { $file = file_load($form_state['storage']['upload']); if (!field_info_instances('file', $form_state['storage']['type'])) { // This filetype doesn't have fields, save the file. @@ -412,15 +415,13 @@ function file_entity_add_upload_submit($form, &$form_state) { } } - // Form id's can vary depending on how many other forms are displayed, so we - // need to do string comparissons. e.g edit-submit--2. - if (strpos($trigger, 'edit-next') !== FALSE) { + if ($trigger == 'next') { $form_state['step'] = $form['#step'] + 1; } - elseif (strpos($trigger, 'edit-previous') !== FALSE) { + elseif ($trigger == 'previous') { $form_state['step'] = $form['#step'] - 1; } - elseif (strpos($trigger, 'edit-submit') !== FALSE) { + elseif ($trigger == 'submit') { $save = TRUE; }