You are here

public function EntityContentBase::rollback in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php \Drupal\migrate\Plugin\migrate\destination\EntityContentBase::rollback()
  2. 9 core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php \Drupal\migrate\Plugin\migrate\destination\EntityContentBase::rollback()

Delete the specified destination object from the target Drupal.

Parameters

array $destination_identifier: The ID of the destination object to delete.

Overrides Entity::rollback

1 method overrides EntityContentBase::rollback()
EntityContentComplete::rollback in core/modules/migrate/src/Plugin/migrate/destination/EntityContentComplete.php
Delete the specified destination object from the target Drupal.

File

core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php, line 376

Class

EntityContentBase
Provides destination class for all content entities lacking a specific class.

Namespace

Drupal\migrate\Plugin\migrate\destination

Code

public function rollback(array $destination_identifier) {
  if ($this
    ->isTranslationDestination()) {

    // Attempt to remove the translation.
    $entity = $this->storage
      ->load(reset($destination_identifier));
    if ($entity && $entity instanceof TranslatableInterface) {
      if ($key = $this
        ->getKey('langcode')) {
        if (isset($destination_identifier[$key])) {
          $langcode = $destination_identifier[$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();
            }
          }
        }
      }
    }
  }
  else {
    parent::rollback($destination_identifier);
  }
}