public function JobCheckoutManager::checkoutMultiple in Translation Management Tool 8
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
\Drupal\tmgmt\JobInterface[] $jobs: The jobs to be checked out.
bool $skip_request_translation: (optional) If TRUE, the jobs that can be submitted immediately will be prepared but not submitted yet. They will not be returned, the caller is responsible for submitting them.
Return value
\Drupal\tmgmt\JobInterface[] List of jobs that have not been submitted immediately and need to be processed.
See also
\Drupal\tmgmt\JobCheckoutManager::checkoutAndRedirect()
Related topics
1 call to JobCheckoutManager::checkoutMultiple()
- JobCheckoutManager::checkoutAndRedirect in src/
JobCheckoutManager.php - Attempts to checkout a number of jobs and prepare the necessary redirects.
File
- src/
JobCheckoutManager.php, line 145
Class
- JobCheckoutManager
- Provides functionality related to job checkout and submissions.
Namespace
Drupal\tmgmtCode
public function checkoutMultiple(array $jobs, $skip_request_translation = FALSE) {
$remaining_jobs = array();
// Allow other modules to jump in and eg. auto-checkout with rules or use a
// customized checkout form.
$this->moduleHandler
->alter('tmgmt_job_checkout_before', $remaining_jobs, $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 (!$this->configFactory
->get('tmgmt.settings')
->get('quick_checkout') || $this
->needsCheckoutForm($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;
}
$remaining_jobs[] = $job;
}
else {
// 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();
if (!$skip_request_translation) {
$this
->requestTranslation($job);
}
}
}
// Allow other modules to jump in and eg. auto-checkout with rules or use a
// customized checkout form.
$this->moduleHandler
->alter('tmgmt_job_checkout_after', $remaining_jobs, $jobs);
// Display message for created jobs that can not be checked out.
if ($denied) {
$this
->messenger()
->addStatus($this
->getStringTranslation()
->formatPlural($denied, 'One job has been created.', '@count jobs have been created.'));
}
return $remaining_jobs;
}