isTranslationDestination example

public function import(Row $row, array $old_destination_id_values = []) {
    $this->rollbackAction = MigrateIdMapInterface::ROLLBACK_DELETE;
    $entity = $this->getEntity($row$old_destination_id_values);
    if (!$entity) {
      throw new MigrateException('Unable to get entity');
    }
    assert($entity instanceof ContentEntityInterface);
    if ($this->isEntityValidationRequired($entity)) {
      $this->validateEntity($entity);
    }
    $ids = $this->save($entity$old_destination_id_values);
    if ($this->isTranslationDestination()) {
      $ids[] = $entity->language()->getId();
    }
    return $ids;
  }

  /** * {@inheritdoc} */
  public function isEntityValidationRequired(FieldableEntityInterface $entity) {
    // Prioritize the entity method over migration config because it won't be     // possible to save that entity unvalidated.

  public function __construct(array $configuration$plugin_id$plugin_definition, MigrationInterface $migration, ConfigFactoryInterface $config_factory, LanguageManagerInterface $language_manager) {
    parent::__construct($configuration$plugin_id$plugin_definition$migration);
    $this->config = $config_factory->getEditable($configuration['config_name']);
    $this->language_manager = $language_manager;
    if ($this->isTranslationDestination()) {
      $this->supportsRollback = TRUE;
    }
  }

  /** * {@inheritdoc} */
  public static function create(ContainerInterface $container, array $configuration$plugin_id$plugin_definition, MigrationInterface $migration = NULL) {
    return new static(
      $configuration,
      $plugin_id,
      

  public function getIds() {
    $ids = [];

    $revision_key = $this->getKey('revision');
    if (!$revision_key) {
      throw new MigrateException(sprintf('The "%s" entity type does not support revisions.', $this->storage->getEntityTypeId()));
    }
    $ids[$revision_key] = $this->getDefinitionFromEntity($revision_key);

    if ($this->isTranslationDestination()) {
      $langcode_key = $this->getKey('langcode');
      if (!$langcode_key) {
        throw new MigrateException(sprintf('The "%s" entity type does not support translations.', $this->storage->getEntityTypeId()));
      }
      $ids[$langcode_key] = $this->getDefinitionFromEntity($langcode_key);
    }

    return $ids;
  }

  /** * {@inheritdoc} */

class EntityFieldInstance extends EntityConfigBase {

  /** * {@inheritdoc} */
  public function getIds() {
    $ids['entity_type']['type'] = 'string';
    $ids['bundle']['type'] = 'string';
    $ids['field_name']['type'] = 'string';
    if ($this->isTranslationDestination()) {
      $ids['langcode']['type'] = 'string';
    }
    return $ids;
  }

}

class EntityFieldStorageConfig extends EntityConfigBase {

  /** * {@inheritdoc} */
  public function getIds() {
    $ids['entity_type']['type'] = 'string';
    $ids['field_name']['type'] = 'string';
    // @todo: Remove conditional. https://www.drupal.org/node/3004574     if ($this->isTranslationDestination()) {
      $ids['langcode']['type'] = 'string';
    }
    return $ids;
  }

  /** * {@inheritdoc} */
  public function rollback(array $destination_identifier) {
    if ($this->isTranslationDestination()) {
      $language = $destination_identifier['langcode'];
      
$migration_ids = array_keys($migrations);
    // Check if there are conflicts. If none, just skip this form!     $migrations = $this->migrationPluginManager->createInstances($migration_ids);

    $translated_content_conflicts = $content_conflicts = [];

    $results = (new IdAuditor())->auditMultiple($migrations);

    /** @var \Drupal\migrate\Audit\AuditResult $result */
    foreach ($results as $result) {
      $destination = $result->getMigration()->getDestinationPlugin();
      if ($destination instanceof EntityContentBase && $destination->isTranslationDestination()) {
        // Translations are not yet supported by the audit system. For now, we         // only warn the user to be cautious when migrating translated content.         // I18n support should be added in https://www.drupal.org/node/2905759.         $translated_content_conflicts[] = $result;
      }
      elseif (!$result->passed()) {
        $content_conflicts[] = $result;
      }
    }

    if ($content_conflicts || $translated_content_conflicts) {
      
$id_key = $this->getKey('id');
    if (count($ids) > 1) {
      // Ids is keyed by the key name so grab the keys.       $id_keys = array_keys($ids);
      if (!$row->getDestinationProperty($id_key)) {
        // Set the ID into the destination in for form "val1.val2.val3".         $row->setDestinationProperty($id_key$this->generateId($row$id_keys));
      }
    }
    $entity = $this->getEntity($row$old_destination_id_values);
    // Translations are already saved in updateEntity by configuration override.     if (!$this->isTranslationDestination()) {
      $entity->save();
    }
    if (count($ids) > 1) {
      // This can only be a config entity, content entities have their ID key       // and that's it.       $return = [];
      foreach ($id_keys as $id_key) {
        if (($this->isTranslationDestination()) && ($id_key == 'langcode')) {
          // Config entities do not have a language property, get the language           // code from the destination.           $return[] = $row->getDestinationProperty($id_key);
        }
Home | Imprint | This part of the site doesn't use cookies.