diff --git a/sources/entity/ui/tmgmt_entity_ui.pages.inc b/sources/entity/ui/tmgmt_entity_ui.pages.inc index 5b1c85b..7a02ce3 100644 --- a/sources/entity/ui/tmgmt_entity_ui.pages.inc +++ b/sources/entity/ui/tmgmt_entity_ui.pages.inc @@ -126,16 +126,5 @@ function tmgmt_entity_ui_translate_form_submit($form, &$form_state) { drupal_set_message(t('Unable to add job item for target language %name. Make sure the source content is not empty.', array('%name' => $target_lang_name)), 'error'); } } - $redirects = tmgmt_ui_job_checkout_multiple($jobs); - // If necessary, do a redirect. - if ($redirects) { - tmgmt_ui_redirect_queue_set($redirects, isset($_GET['destination']) ? $_GET['destination'] : current_path()); - // Remove an eventually existing destination, as that will prevent us - // from being redirect to the job checkout page. - unset($_GET['destination']); - $form_state['redirect'] = tmgmt_ui_redirect_queue_dequeue(); - - // Count of the job messages is one less due to the final redirect. - drupal_set_message(format_plural(count($redirects), t('One job needs to be checked out.'), t('@count jobs need to be checked out.'))); - } + tmgmt_ui_job_checkout_and_redirect($form_state, $jobs); } diff --git a/sources/i18n_string/tmgmt_i18n_string.module b/sources/i18n_string/tmgmt_i18n_string.module index 20d5627..75eec31 100644 --- a/sources/i18n_string/tmgmt_i18n_string.module +++ b/sources/i18n_string/tmgmt_i18n_string.module @@ -174,19 +174,7 @@ function tmgmt_i18n_string_translate_form_submit($form, &$form_state) { $jobs[$target_lang_registry[$target_lang]]->addItem('i18n_string', $type, $key); } } - - $redirects = tmgmt_ui_job_checkout_multiple($jobs); - // If necessary, do a redirect. - if ($redirects) { - tmgmt_ui_redirect_queue_set($redirects, isset($_GET['destination']) ? $_GET['destination'] : current_path()); - // Remove an eventually existing destination, as that will prevent us - // from being redirect to the job checkout page. - unset($_GET['destination']); - $form_state['redirect'] = tmgmt_ui_redirect_queue_dequeue(); - - // Count of the job messages is one less due to the final redirect. - drupal_set_message(format_plural(count($redirects), t('One job needs to be checked out.'), t('@count jobs need to be checked out.'))); - } + tmgmt_ui_job_checkout_and_redirect($form_state, $jobs); } /** diff --git a/sources/node/ui/tmgmt_node_ui.pages.inc b/sources/node/ui/tmgmt_node_ui.pages.inc index ffd27dd..e02be6d 100644 --- a/sources/node/ui/tmgmt_node_ui.pages.inc +++ b/sources/node/ui/tmgmt_node_ui.pages.inc @@ -100,16 +100,5 @@ function tmgmt_node_ui_translate_form_submit($form, &$form_state) { // to a multistep checkout form if necessary. $jobs[$job->tjid] = $job; } - $redirects = tmgmt_ui_job_checkout_multiple($jobs); - // If necessary, do a redirect. - if ($redirects) { - tmgmt_ui_redirect_queue_set($redirects, isset($_GET['destination']) ? $_GET['destination'] : current_path()); - // Remove an eventually existing destination, as that will prevent us - // from being redirect to the job checkout page. - unset($_GET['destination']); - $form_state['redirect'] = tmgmt_ui_redirect_queue_dequeue(); - - // Count of the job messages is one less due to the final redirect. - drupal_set_message(format_plural(count($redirects), t('One job needs to be checked out.'), t('@count jobs need to be checked out.'))); - } + tmgmt_ui_job_checkout_and_redirect($form_state, $jobs); } diff --git a/ui/tmgmt_ui.module b/ui/tmgmt_ui.module index dcfb8ef..71bee54 100644 --- a/ui/tmgmt_ui.module +++ b/ui/tmgmt_ui.module @@ -269,7 +269,9 @@ function tmgmt_ui_source_overview_form_submit($form, &$form_state) { * Array of redirect url's if there are any jobs that need manual checkout. * * @ingroup tmgmt_job + * * @see tmgmt_ui_redirect_queue() + * @see tmgmt_ui_job_checkout_and_redirect() */ function tmgmt_ui_job_checkout_multiple(array $jobs) { $redirects = array(); @@ -976,6 +978,38 @@ function tmgmt_ui_color_legend() { return $output; } +/** + * Attempts to checkout a number of jobs and prepare the necessary redirects. + * + * @param array $form_state + * Form state array, used to set the initial redirect. + * @param array $jobs + * Array of jobs to attempt checkout + * + * @ingroup tmgmt_job + * + * @see tmgmt_ui_job_checkout_multiple() + */ +function tmgmt_ui_job_checkout_and_redirect(array &$form_state, array $jobs) { + $redirects = tmgmt_ui_job_checkout_multiple($jobs); + // If necessary, do a redirect. + if ($redirects) { + if (isset($_GET['destination'])) { + // Remove existing destination, as that will prevent us from being + // redirect to the job checkout page. Set the destination as the final + // redirect instead. + tmgmt_ui_redirect_queue_set($redirects, $_GET['destination']); + unset($_GET['destination']); + } + else { + tmgmt_ui_redirect_queue_set($redirects, current_path()); + } + $form_state['redirect'] = tmgmt_ui_redirect_queue_dequeue(); + + // Count of the job messages is one less due to the final redirect. + drupal_set_message(format_plural(count($redirects), t('One job needs to be checked out.'), t('@count jobs need to be checked out.'))); + } +} /** * Implements hook_help(). @@ -987,4 +1021,4 @@ function tmgmt_ui_help($path, $arg) { } return $output; -} \ No newline at end of file +}