function ModerationLocaleTest::loadTranslation

Same name in other branches
  1. 8.9.x core/modules/content_moderation/tests/src/Functional/ModerationLocaleTest.php \Drupal\Tests\content_moderation\Functional\ModerationLocaleTest::loadTranslation()
  2. 10 core/modules/content_moderation/tests/src/Functional/ModerationLocaleTest.php \Drupal\Tests\content_moderation\Functional\ModerationLocaleTest::loadTranslation()
  3. 11.x core/modules/content_moderation/tests/src/Functional/ModerationLocaleTest.php \Drupal\Tests\content_moderation\Functional\ModerationLocaleTest::loadTranslation()

Loads the node translation for the specified language.

Parameters

\Drupal\node\NodeInterface $node: A node object.

string $langcode: The translation language code.

Return value

\Drupal\node\NodeInterface The node translation object.

1 call to ModerationLocaleTest::loadTranslation()
ModerationLocaleTest::testLanguageIndependentContentModeration in core/modules/content_moderation/tests/src/Functional/ModerationLocaleTest.php
Tests that individual translations can be moderated independently.

File

core/modules/content_moderation/tests/src/Functional/ModerationLocaleTest.php, line 492

Class

ModerationLocaleTest
Test content_moderation functionality with localization and translation.

Namespace

Drupal\Tests\content_moderation\Functional

Code

protected function loadTranslation(NodeInterface $node, $langcode) {
    
    /** @var \Drupal\node\NodeStorageInterface $storage */
    $storage = $this->container
        ->get('entity_type.manager')
        ->getStorage('node');
    // Explicitly invalidate the cache for that node, as the call below is
    // statically cached.
    $storage->resetCache([
        $node->id(),
    ]);
    
    /** @var \Drupal\node\NodeInterface $node */
    $node = $storage->loadRevision($storage->getLatestRevisionId($node->id()));
    return $node->getTranslation($langcode);
}

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