You are here

public function Job::requestTranslation in Translation Management Tool 8

Request the translation of a job from the translator.

Return value

int The updated job status.

Overrides JobInterface::requestTranslation

File

src/Entity/Job.php, line 728

Class

Job
Entity class for the tmgmt_job entity.

Namespace

Drupal\tmgmt\Entity

Code

public function requestTranslation() {
  if (!$this
    ->canRequestTranslation()
    ->getSuccess()) {
    return FALSE;
  }
  if (!$this
    ->isContinuous()) {
    $this
      ->setOwnerId(\Drupal::currentUser()
      ->id());
  }

  // Call the hook before requesting the translation.
  \Drupal::moduleHandler()
    ->invokeAll('tmgmt_job_before_request_translation', [
    $this
      ->getItems(),
  ]);

  // We do not want to translate the items that are already translated.
  $this->filterTranslatedItems = TRUE;

  // We don't know if the translator plugin already processed our
  // translation request after this point. That means that the plugin has to
  // set the 'submitted', 'needs review', etc. states on its own.
  if (!empty($this
    ->getItems())) {
    $this
      ->getTranslatorPlugin()
      ->requestTranslation($this);
  }
  else {
    $this
      ->submitted();
  }

  // Reset it again so getData returns again all the values.
  $this->filterTranslatedItems = FALSE;

  // Call the hook after requesting the translation.
  \Drupal::moduleHandler()
    ->invokeAll('tmgmt_job_after_request_translation', [
    $this
      ->getItems(),
  ]);
}