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.
\Drupal\tmgmt\JobInterface[] $jobs: The jobs to be checked out.
Array of redirect url's if there are any jobs that need manual checkout.
Deprecated in 8.x-1.x, use \Drupal\tmgmt\JobCheckoutManager::checkoutMultiple() instead.
tmgmt_redirect_queue()
tmgmt_job_checkout_and_redirect()
function tmgmt_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::moduleHandler()
->alter('tmgmt_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 (!\Drupal::config('tmgmt.settings')
->get('quick_checkout') || tmgmt_job_needs_checkout_form($job)) {
if (!$job
->access('submit')) {
// Ignore jobs if the user is not allowed to submit, ignore.
$denied++;
// Make sure that the job is saved.
$job
->save();
continue;
}
$redirects[] = $job
->toUrl()
->getInternalPath();
}
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, save the job
// in case someone excepts to be able to load the job and have the
// translator available.
$job
->save();
tmgmt_job_request_translation($job);
}
}
// Allow other modules to jump in and eg. auto-checkout with rules or use a
// customized checkout form.
\Drupal::moduleHandler()
->alter('tmgmt_job_checkout_after', $redirects, $jobs);
// Display message for created jobs that can not be checked out.
if ($denied) {
\Drupal::messenger()
->addStatus(\Drupal::translation()
->formatPlural($denied, 'One job has been created.', '@count jobs have been created.'));
}
return $redirects;
}