setRevisionTranslationAffected example

$this->assertTrue(
      $this->getRevisionTranslationAffectedFlag($french),
      'Changed flag of French translation is set when adding the translation and a new revision.'
    );

    // Since above a clone of the entity was saved and then this entity is saved     // again, we have to update the revision ID to the current one.     $german->set('revision_id', $form_entity_builder_clone->getRevisionId());
    $german->updateLoadedRevisionId();
    $german->setOwner($user1);
    $german->setRevisionTranslationAffected(FALSE);
    $entity->save();

    $this->assertFalse(
      $this->getRevisionTranslationAffectedFlag($german),
      'German translation changed but the changed flag is reset manually.'
    );

    $entity->setNewRevision();
    $german->setRevisionTranslationAffected(TRUE);
    $entity->save();

    
/** @var \Drupal\Core\Field\FieldItemListInterface[] $sync_items */
        $sync_items = array_diff_key(
          $keep_untranslatable_fields ? $default_revision_translation->getTranslatableFields() : $default_revision_translation->getFields(),
          $skipped_field_names
        );
        foreach ($sync_items as $field_name => $items) {
          $new_revision_translation->set($field_name$items->getValue());
        }

        // Make sure the "revision_translation_affected" flag is recalculated.         $new_revision_translation->setRevisionTranslationAffected(NULL);

        // No need to copy untranslatable field values more than once.         $keep_untranslatable_fields = TRUE;
      }

      // Make sure we do not inadvertently recreate removed translations.       foreach (array_diff_key($new_revision->getTranslationLanguages()$translation_languages) as $langcode => $language) {
        // Allow a new revision to be created for the active language.         if ($langcode !== $active_langcode) {
          $new_revision->removeTranslation($langcode);
        }
      }
parent::setUp();
    $this->drupalLogin($this->adminUser);
    $this->drupalPlaceBlock('page_title_block');
  }

  /** * Tests revision revert. */
  public function testRevertForm(): void {
    $entity = $this->createBlockContent(save: FALSE)
      ->setRevisionCreationTime((new \DateTimeImmutable('11 January 2009 4pm'))->getTimestamp())
      ->setRevisionTranslationAffected(TRUE);
    $entity->setNewRevision();
    $entity->save();
    $revisionId = $entity->getRevisionId();

    // Cannot revert latest revision.     $this->drupalGet($entity->toUrl('revision-revert-form'));
    $this->assertSession()->statusCodeEquals(403);

    // Create a new latest revision.     $entity
      ->setRevisionCreationTime((new \DateTimeImmutable('11 January 2009 5pm'))->getTimestamp())
      
parent::setUp();
    $this->drupalLogin($this->adminUser);
    $this->drupalPlaceBlock('page_title_block');
  }

  /** * Tests revision delete. */
  public function testDeleteForm(): void {
    $entity = $this->createBlockContent(save: FALSE)
      ->setRevisionCreationTime((new \DateTimeImmutable('11 January 2009 4pm'))->getTimestamp())
      ->setRevisionTranslationAffected(TRUE);
    $entity->setNewRevision();
    $entity->save();
    $revisionId = $entity->getRevisionId();

    // Cannot delete latest revision.     $this->drupalGet($entity->toUrl('revision-delete-form'));
    $this->assertSession()->statusCodeEquals(403);

    // Create a new latest revision.     $entity
      ->setRevisionCreationTime((new \DateTimeImmutable('11 January 2009 5pm'))->getTimestamp())
      
// Update the revision metadata fields and the changed field, which should     // be skipped from checking for changes in     // ContentEntityBase::hasTranslationChanges().     $entity_previous_rev_id = $entity->getRevisionId();
    // Revision metadata field revision_timestamp.     $entity->setRevisionCreationTime(time() + 1);
    // Revision metadata field revision_uid.     $entity->setRevisionUserId($user2->id());
    // Revision metadata field revision_log.     $entity->setRevisionLogMessage('test');
    // Revision metadata field revision_translation_affected.     $entity->setRevisionTranslationAffected(TRUE);
    // Changed field.     $entity->setChangedTime(time() + 1);

    // Check that the revision metadata fields and the changed field have been     // skipped when comparing same revisions.     $this->assertFalse($entity->hasTranslationChanges(), 'ContentEntityBase::hasTranslationChanges() found no changes when comparing different revisions.');

    // Check that the revision metadata fields and the changed field have been     // skipped when comparing same revisions with enforced new revision to be     // created on save.     $entity->setNewRevision(TRUE);
    

  public function prepareTranslation(ContentEntityInterface $entity, LanguageInterface $source, LanguageInterface $target) {
    $source_langcode = $source->getId();
    /** @var \Drupal\Core\Entity\ContentEntityInterface $source_translation */
    $source_translation = $entity->getTranslation($source_langcode);
    $target_translation = $entity->addTranslation($target->getId()$source_translation->toArray());

    // Make sure we do not inherit the affected status from the source values.     if ($entity->getEntityType()->isRevisionable()) {
      $target_translation->setRevisionTranslationAffected(NULL);
    }

    /** @var \Drupal\user\UserInterface $user */
    $user = $this->entityTypeManager()->getStorage('user')->load($this->currentUser()->id());
    $metadata = $this->manager->getTranslationMetadata($target_translation);

    // Update the translation author to current user, as well the translation     // creation time.     $metadata->setAuthor($user);
    $metadata->setCreatedTime(REQUEST_TIME);
    $metadata->setSource($source_langcode);
  }
Home | Imprint | This part of the site doesn't use cookies.