You are here

protected function EntityReferenceRevisions::rollbackTranslation in Entity Reference Revisions 8

Rollback translation destinations.

Parameters

array $destination_identifiers: The IDs of the destination object to delete.

1 call to EntityReferenceRevisions::rollbackTranslation()
EntityReferenceRevisions::rollback in src/Plugin/migrate/destination/EntityReferenceRevisions.php
Delete the specified destination object from the target Drupal.

File

src/Plugin/migrate/destination/EntityReferenceRevisions.php, line 173

Class

EntityReferenceRevisions
Provides entity_reference_revisions destination plugin.

Namespace

Drupal\entity_reference_revisions\Plugin\migrate\destination

Code

protected function rollbackTranslation(array $destination_identifiers) {
  $entity = $this->storage
    ->loadRevision(array_pop($destination_identifiers));
  if ($entity && $entity instanceof TranslatableInterface) {
    if ($key = $this
      ->getKey('langcode')) {
      if (isset($destination_identifiers[$key])) {
        $langcode = $destination_identifiers[$key];
        if ($entity
          ->hasTranslation($langcode)) {

          // Make sure we don't remove the default translation.
          $translation = $entity
            ->getTranslation($langcode);
          if (!$translation
            ->isDefaultTranslation()) {
            $entity
              ->removeTranslation($langcode);
            $entity
              ->save();
          }
        }
      }
    }
  }
}