/** * Helper function to obtain a locale object for given job item. * * @param \Drupal\tmgmt\JobItemInterface $job_item * * @return locale object */ protected function getLocaleObject(JobItemInterface $job_item) { $locale_lid = $job_item->getItemId(); // Check existence of assigned lid. $exists = db_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 = db_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 = db_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; }
/** * {@inheritdoc} */ public function rejectDataItem(JobItemInterface $job_item, array $key, array $values = NULL) { $key = '[' . implode('][', $key) . ']'; $job_item->addMessage('Rejected data item @key for job item @item in job @job.', array('@key' => $key, '@item' => $job_item->id(), '@job' => $job_item->getJobId())); return TRUE; }