You are here

public function Job::cleanSuggestionsList in Translation Management Tool 8

Removes all suggestions from the given list which should not be processed.

This function removes all suggestions from the given list which are already assigned to a translation job or which should not be processed because there are no words, no translation is needed, ...

Parameters

array &$suggestions: Associative array of translation suggestions. It must contain at least:

  • tmgmt_job: An instance of aJobItem.

Overrides JobInterface::cleanSuggestionsList

File

src/Entity/Job.php, line 933

Class

Job
Entity class for the tmgmt_job entity.

Namespace

Drupal\tmgmt\Entity

Code

public function cleanSuggestionsList(array &$suggestions) {
  foreach ($suggestions as $k => $suggestion) {
    if (is_array($suggestion) && isset($suggestion['job_item']) && $suggestion['job_item'] instanceof JobItem) {
      $jobItem = $suggestion['job_item'];

      // Items with no words to translate should not be presented.
      if ($jobItem
        ->getWordCount() <= 0) {
        unset($suggestions[$k]);
        continue;
      }

      // Check if there already exists a translation job for this item in the
      // current language.
      $items = tmgmt_job_item_load_all_latest($jobItem
        ->getPlugin(), $jobItem
        ->getItemType(), $jobItem
        ->getItemId(), $this
        ->getSourceLangcode());
      if (isset($items[$this
        ->getTargetLangcode()])) {
        unset($suggestions[$k]);
        continue;
      }

      // If the item is part of the current job, no matter which language,
      // remove it.
      foreach ($items as $item) {
        if ($item
          ->getJobId() == $this
          ->id()) {
          unset($suggestions[$k]);
          continue;
        }
      }
    }
    else {
      unset($suggestions[$k]);
      continue;
    }
  }
}