You are here

public function JobCheckoutManager::needsCheckoutForm 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

bool TRUE if the job needs a checkout form.

1 call to JobCheckoutManager::needsCheckoutForm()
JobCheckoutManager::checkoutMultiple in src/JobCheckoutManager.php
Attempts to check out a number of jobs.

File

src/JobCheckoutManager.php, line 203

Class

JobCheckoutManager
Provides functionality related to job checkout and submissions.

Namespace

Drupal\tmgmt

Code

public function needsCheckoutForm(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;
}