You are here

function tmgmt_ui_job_checkout_multiple in Translation Management Tool 7

Attempts to check out a number of jobs. Performs a number of checks on each job and also allows to alter the behavior through hooks.

Parameters

$jobs: The jobs to be checked out.

Return value

Array of redirect url's if there are any jobs that need manual checkout.

See also

tmgmt_ui_redirect_queue()

tmgmt_ui_job_checkout_and_redirect()

Related topics

7 calls to tmgmt_ui_job_checkout_multiple()
TMGMTEntitySourceUIController::overviewFormSubmit in sources/entity/ui/tmgmt_entity_ui.ui.inc
TMGMTUITestCase::testCheckoutForm in ui/tmgmt_ui.test
Test the page callbacks to create jobs and check them out.
TMGMTUITestCase::testCheckoutFunction in ui/tmgmt_ui.test
Tests the tmgmt_ui_job_checkout() function.
TMGMTUITestCase::testSuggestions in ui/tmgmt_ui.test
Tests the UI of suggestions.
tmgmt_node_ui_checkout_multiple_action in sources/node/ui/tmgmt_node_ui.module
Action to do multistep checkout for translations.

... See full list

File

ui/tmgmt_ui.module, line 436
Common Translation managment UI.

Code

function tmgmt_ui_job_checkout_multiple(array $jobs) {
  $redirects = array();

  // Allow other modules to jump in and eg. auto-checkout with rules or use a
  // customized checkout form.
  drupal_alter('tmgmt_ui_job_checkout_before', $redirects, $jobs);
  $denied = 0;
  foreach ($jobs as $job) {
    if (!$job
      ->isUnprocessed()) {

      // Job is already checked out, just ignore that one. This could happen
      // if jobs have already been submitted in the before hook.
      continue;
    }
    if (!variable_get('tmgmt_quick_checkout', TRUE) || tmgmt_ui_job_needs_checkout_form($job)) {
      if (!entity_access('submit', 'tmgmt_job', $job)) {

        // Ignore jobs if the user is not allowed to submit, ignore.
        $denied++;

        // Make sure that the job is saved.
        $job
          ->save();
        continue;
      }
      $uri = $job
        ->uri();
      $redirects[] = $uri['path'];
    }
    else {

      // @todo this is dangerous because we don't catch request fails at all.
      // Normally I would expect this to catch all failed requests and
      // afterwards send the user through a multistep form which contains the
      // failed elements.
      // No manual checkout required. Request translations now.
      tmgmt_ui_job_request_translation($job);
    }
  }

  // Allow other modules to jump in and eg. auto-checkout with rules or use a
  // customized checkout form.
  drupal_alter('tmgmt_ui_job_checkout_after', $redirects, $jobs);

  // Display message for created jobs that can not be checked out.
  if ($denied) {
    drupal_set_message(format_plural($denied, 'One job has been created.', '@count jobs have been created.'));
  }
  return $redirects;
}