You are here

public function ContentEntitySource::saveTranslation in Translation Management Tool 8

Saves a translation.

Parameters

\Drupal\tmgmt\JobItemInterface $job_item: The job item entity.

string $target_langcode: The target language code.

Return value

bool TRUE if the translation was saved successfully, FALSE otherwise.

Overrides SourcePluginInterface::saveTranslation

File

sources/content/src/Plugin/tmgmt/Source/ContentEntitySource.php, line 381

Class

ContentEntitySource
Content entity source plugin controller.

Namespace

Drupal\tmgmt_content\Plugin\tmgmt\Source

Code

public function saveTranslation(JobItemInterface $job_item, $target_langcode) {

  /* @var \Drupal\Core\Entity\ContentEntityInterface $entity */
  $entity = $this
    ->getEntity($job_item);
  if (!$entity) {
    $job_item
      ->addMessage('The entity %id of type %type does not exist, the job can not be completed.', array(
      '%id' => $job_item
        ->getItemId(),
      '%type' => $job_item
        ->getItemType(),
    ), 'error');
    return FALSE;
  }

  /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
  if ($entity_revision = $this
    ->getPendingRevisionWithCompositeReferenceField($job_item)) {
    $title = $entity_revision
      ->hasLinkTemplate('latest-version') ? $entity_revision
      ->toLink(NULL, 'latest-version')
      ->toString() : $entity_revision
      ->label();
    $job_item
      ->addMessage('This translation cannot be accepted as there is a pending revision in the default translation. You must publish %title first before saving this translation.', [
      '%title' => $title,
    ], 'error');
    return FALSE;
  }
  $data = $job_item
    ->getData();
  $this
    ->doSaveTranslations($entity, $data, $target_langcode, $job_item);
  return TRUE;
}