Exemple #1
0
 /**
  * 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;
 }
 /**
  * The _title_callback for the page that renders a single node in preview.
  *
  * @param \Drupal\tmgmt\JobItemInterface $tmgmt_job_item
  *   The current node.
  *
  * @return string
  *   The page title.
  */
 public function title(JobItemInterface $tmgmt_job_item)
 {
     $target_language = $tmgmt_job_item->getJob()->getTargetLanguage()->getName();
     $title = $this->entityTypeManager->getStorage($tmgmt_job_item->getItemType())->load($tmgmt_job_item->getItemId())->getTitle();
     return t("Preview of @title for @target_language", ['@title' => $title, '@target_language' => $target_language]);
 }
 /**
  * Builds the translation status render array with source and job item status.
  *
  * @param int $status
  *   The source status: original, missing, current or outofdate.
  * @param \Drupal\tmgmt\JobItemInterface|NULL $job_item
  *   The existing job item for the source.
  *
  * @return array
  *   The render array for displaying the status.
  */
 function buildTranslationStatus($status, JobItemInterface $job_item = NULL)
 {
     switch ($status) {
         case 'original':
             $label = t('Source language');
             $icon = 'core/misc/icons/bebebe/house.svg';
             break;
         case 'missing':
             $label = t('Not translated');
             $icon = 'core/misc/icons/bebebe/ex.svg';
             break;
         case 'outofdate':
             $label = t('Translation Outdated');
             $icon = drupal_get_path('module', 'tmgmt') . '/icons/outdated.svg';
             break;
         default:
             $label = t('Translation up to date');
             $icon = 'core/misc/icons/73b355/check.svg';
     }
     $build['source'] = ['#theme' => 'image', '#uri' => $icon, '#title' => $label, '#alt' => $label];
     // If we have an active job item, wrap it in a link.
     if ($job_item) {
         $states_labels = JobItem::getStates();
         $state_label = $states_labels[$job_item->getState()];
         $label = t('Active job item: @state', array('@state' => $state_label));
         $url = $job_item->toUrl();
         $job = $job_item->getJob();
         switch ($job_item->getState()) {
             case JobItem::STATE_ACTIVE:
                 if ($job->isUnprocessed()) {
                     $url = $job->toUrl();
                     $label = t('Active job item: @state', array('@state' => $state_label));
                 }
                 $icon = drupal_get_path('module', 'tmgmt') . '/icons/hourglass.svg';
                 break;
             case JobItem::STATE_REVIEW:
                 $icon = drupal_get_path('module', 'tmgmt') . '/icons/ready.svg';
                 break;
         }
         $url->setOption('query', \Drupal::destination()->getAsArray());
         $url->setOption('attributes', array('title' => $label));
         $item_icon = ['#theme' => 'image', '#uri' => $icon, '#title' => $label, '#alt' => $label];
         $build['job_item'] = ['#type' => 'link', '#url' => $url, '#title' => $item_icon];
     }
     return $build;
 }
 /**
  * {@inheritdoc}
  */
 public function getPreviewUrl(JobItemInterface $job_item)
 {
     if ($job_item->getJob()->isActive() && !($job_item->isAborted() || $job_item->isAccepted())) {
         return new Url('tmgmt_content.job_item_preview', ['tmgmt_job_item' => $job_item->id()], ['query' => ['key' => \Drupal::service('tmgmt_content.key_access')->getKey($job_item)]]);
     } else {
         return NULL;
     }
 }