Returns a job which matches the requested source- and target language by user. If no job exists, a new job object will be created.
$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.
\Drupal\tmgmt\JobInterface The job entity.
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());
}