setRollbackAction example

foreach ($row->getDestination() as $field_name => $values) {
      $field = $entity->$field_name;
      if ($field instanceof TypedDataInterface) {
        $field->setValue($values);
      }
    }
    foreach ($empty_destinations as $field_name) {
      $entity->$field_name = NULL;
    }

    $this->setRollbackAction($row->getIdMap()$rollback_action);

    // We might have a different (translated) entity, so return it.     return $entity;
  }

  /** * Populates as much of the stub row as possible. * * @param \Drupal\migrate\Row $row * The row of data. */
  
if (!$row->hasDestinationProperty('translation')) {
        throw new \LogicException('The "translation" property is required');
      }
      $config_override = $this->languageManager->getLanguageConfigOverride($row->getDestinationProperty('langcode')$config);
      $config_override->set(str_replace(Row::PROPERTY_SEPARATOR, '.', $row->getDestinationProperty('property'))$row->getDestinationProperty('translation'));
      $config_override->save();
    }
    else {
      foreach ($row->getRawDestination() as $property => $value) {
        $this->updateEntityProperty($entityexplode(Row::PROPERTY_SEPARATOR, $property)$value);
      }
      $this->setRollbackAction($row->getIdMap());
    }
  }

  /** * Updates a (possible nested) entity property with a value. * * @param \Drupal\Core\Entity\EntityInterface $entity * The config entity. * @param array $parents * The array of parents. * @param string|object $value * The value to update to. */
return $entity;
  }

  /** * {@inheritdoc} */
  protected function updateEntity(EntityInterface $entity, Row $row) {
    $entity = parent::updateEntity($entity$row);
    // Always set the rollback action to delete. This is because the parent     // updateEntity will set the rollback action to preserve for the original     // language row, which is needed for the classic node migrations.     $this->setRollbackAction($row->getIdMap(), MigrateIdMapInterface::ROLLBACK_DELETE);
    return $entity;
  }

  /** * {@inheritdoc} */
  protected function save(ContentEntityInterface $entity, array $old_destination_id_values = []) {
    parent::save($entity$old_destination_id_values);
    return [
      $entity->id(),
      $entity->getRevisionId(),
    ];
Home | Imprint | This part of the site doesn't use cookies.