function EntityContentBase::rollback

Same name in other branches
  1. 8.9.x core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php \Drupal\migrate\Plugin\migrate\destination\EntityContentBase::rollback()
  2. 10 core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php \Drupal\migrate\Plugin\migrate\destination\EntityContentBase::rollback()
  3. 11.x core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php \Drupal\migrate\Plugin\migrate\destination\EntityContentBase::rollback()

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 374

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);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.