You are here

function tmgmt_job_needs_checkout_form in Translation Management Tool 8

Check if a job needs a checkout form. The current checks include if there is more than one translator available, if he has settings and if the job has a fixed target language.

Parameters

\Drupal\tmgmt\JobInterface $job: The job item

Return value

TRUE if the job needs a checkout form.

Deprecated

Deprecated in 8.x-1.x, use \Drupal\tmgmt\JobCheckoutManager::needsCheckoutForm() instead.

1 call to tmgmt_job_needs_checkout_form()
tmgmt_job_checkout_multiple in ./tmgmt.module
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.

File

./tmgmt.module, line 660
Main module file for the Translation Management module.

Code

function tmgmt_job_needs_checkout_form(JobInterface $job) {

  // If the job has no target language (or source language, even though this
  // should never be the case in our use case), checkout is mandatory.
  if (!$job
    ->getTargetLangcode() || !$job
    ->getSourceLangcode()) {
    return TRUE;
  }

  // If no translator is pre-selected, try to pick one automatically.
  if (!$job
    ->hasTranslator()) {

    // If there is more than a single translator available or if there are no
    // translators available at all checkout is mandatory.
    $translators = tmgmt_translator_load_available($job);
    if (empty($translators) || count($translators) > 1) {
      return TRUE;
    }
    $translator = reset($translators);
    $job->translator = $translator
      ->id();
  }

  // If that translator has settings, the checkout is mandatory.
  if ($job
    ->getTranslator()
    ->hasCheckoutSettings($job)) {
    return TRUE;
  }
  return FALSE;
}