function tmgmt_job_match_item

Returns a job which matches the requested source- and target language by user. If no job exists, a new job object will be created.

Parameters

$source_language: The source language from which should be translated.

$target_language: The target language into which should be translated.

$account: (Optional) A user object. Defaults to the currently logged in user.

Return value

\Drupal\tmgmt\JobInterface The job entity.

Related topics

3 calls to tmgmt_job_match_item()
HelperTest::testTMGTJobMatchItem in tests/src/Kernel/HelperTest.php
Tests tmgmt_job_match_item()
TMGMTUiTest::testCheckoutForm in tests/src/Functional/TMGMTUiTest.php
Test the page callbacks to create jobs and check them out.
TranslatorJavascriptTest::testMultipleLocalToSingleRemoteMapping in tests/src/FunctionalJavascript/TranslatorJavascriptTest.php
Test multiple local language with one single remote language.

File

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

Code

function tmgmt_job_match_item($source_language, $target_language, $account = NULL) {
  $account = isset($account) ? $account : \Drupal::currentUser();
  $tjid = \Drupal::entityQuery('tmgmt_job')
    ->accessCheck(TRUE)
    ->condition('source_language', $source_language)
    ->condition('target_language', $target_language)
    ->condition('uid', $account
    ->id())
    ->condition('state', Job::STATE_UNPROCESSED)
    ->execute();
  if (!empty($tjid)) {
    return Job::load(reset($tjid));
  }
  return tmgmt_job_create($source_language, $target_language, $account
    ->id());
}