function ContentTranslationFieldSyncRevisionTest::createRevision

Same name in other branches
  1. 9 core/modules/content_translation/tests/src/Kernel/ContentTranslationFieldSyncRevisionTest.php \Drupal\Tests\content_translation\Kernel\ContentTranslationFieldSyncRevisionTest::createRevision()
  2. 8.9.x core/modules/content_translation/tests/src/Kernel/ContentTranslationFieldSyncRevisionTest.php \Drupal\Tests\content_translation\Kernel\ContentTranslationFieldSyncRevisionTest::createRevision()
  3. 10 core/modules/content_translation/tests/src/Kernel/ContentTranslationFieldSyncRevisionTest.php \Drupal\Tests\content_translation\Kernel\ContentTranslationFieldSyncRevisionTest::createRevision()

Creates a new revision starting from the latest translation-affecting one.

Parameters

\Drupal\Core\Entity\ContentEntityInterface $translation: The translation to be revisioned.

bool $default: (optional) Whether the new revision should be marked as default. Defaults to TRUE.

Return value

\Drupal\Core\Entity\ContentEntityInterface An entity revision object.

1 call to ContentTranslationFieldSyncRevisionTest::createRevision()
ContentTranslationFieldSyncRevisionTest::testFieldSynchronizationAndValidation in core/modules/content_translation/tests/src/Kernel/ContentTranslationFieldSyncRevisionTest.php
Checks that field synchronization works as expected with revisions.

File

core/modules/content_translation/tests/src/Kernel/ContentTranslationFieldSyncRevisionTest.php, line 514

Class

ContentTranslationFieldSyncRevisionTest
Tests the field synchronization logic when revisions are involved.

Namespace

Drupal\Tests\content_translation\Kernel

Code

protected function createRevision(ContentEntityInterface $translation, $default = TRUE) {
    if (!$translation->isNewTranslation()) {
        $langcode = $translation->language()
            ->getId();
        $revision_id = $this->storage
            ->getLatestTranslationAffectedRevisionId($translation->id(), $langcode);
        
        /** @var \Drupal\Core\Entity\ContentEntityInterface $revision */
        $revision = $this->storage
            ->loadRevision($revision_id);
        $translation = $revision->getTranslation($langcode);
    }
    
    /** @var \Drupal\Core\Entity\ContentEntityInterface $revision */
    $revision = $this->storage
        ->createRevision($translation, $default);
    return $revision;
}

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