Helper function to obtain a locale object for given job item.
\Drupal\tmgmt\JobItemInterface $job_item:
locale object
protected function getLocaleObject(JobItemInterface $job_item) {
$locale_lid = $job_item
->getItemId();
// Check existence of assigned lid.
$exists = \Drupal::database()
->query("SELECT COUNT(lid) FROM {locales_source} WHERE lid = :lid", array(
':lid' => $locale_lid,
))
->fetchField();
if (!$exists) {
throw new TMGMTException(t('Unable to load locale with id %id', array(
'%id' => $job_item
->getItemId(),
)));
}
// This is necessary as the method is also used in the getLabel() callback
// and for that case the job is not available in the cart.
if ($job_item
->getJobId()) {
$source_language = $job_item
->getJob()
->getSourceLangcode();
}
else {
$source_language = $job_item
->getSourceLangCode();
}
if ($source_language == 'en') {
$query = \Drupal::database()
->select('locales_source', 'ls');
$query
->fields('ls')
->condition('ls.lid', $locale_lid);
$locale_object = $query
->execute()
->fetchObject();
$locale_object->language = 'en';
if (empty($locale_object)) {
return NULL;
}
$locale_object->origin = 'source';
}
else {
$query = \Drupal::database()
->select('locales_target', 'lt');
$query
->join('locales_source', 'ls', 'ls.lid = lt.lid');
$query
->fields('lt')
->fields('ls')
->condition('lt.lid', $locale_lid)
->condition('lt.language', $source_language);
$locale_object = $query
->execute()
->fetchObject();
if (empty($locale_object)) {
return NULL;
}
$locale_object->origin = 'target';
}
return $locale_object;
}