You are here

protected function EntityReferenceFieldTranslatedReferenceViewTest::createReferencedEntityWithTranslation in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/field/tests/src/Functional/EntityReference/EntityReferenceFieldTranslatedReferenceViewTest.php \Drupal\Tests\field\Functional\EntityReference\EntityReferenceFieldTranslatedReferenceViewTest::createReferencedEntityWithTranslation()
  2. 9 core/modules/field/tests/src/Functional/EntityReference/EntityReferenceFieldTranslatedReferenceViewTest.php \Drupal\Tests\field\Functional\EntityReference\EntityReferenceFieldTranslatedReferenceViewTest::createReferencedEntityWithTranslation()

Create a referenced entity with a translation.

1 call to EntityReferenceFieldTranslatedReferenceViewTest::createReferencedEntityWithTranslation()
EntityReferenceFieldTranslatedReferenceViewTest::createContent in core/modules/field/tests/src/Functional/EntityReference/EntityReferenceFieldTranslatedReferenceViewTest.php
Creates a test subject contents, with translation.

File

core/modules/field/tests/src/Functional/EntityReference/EntityReferenceFieldTranslatedReferenceViewTest.php, line 297

Class

EntityReferenceFieldTranslatedReferenceViewTest
Tests the translation of entity reference field display on nodes.

Namespace

Drupal\Tests\field\Functional\EntityReference

Code

protected function createReferencedEntityWithTranslation() {

  /** @var \Drupal\node\Entity\Node $node */
  $node = \Drupal::entityTypeManager()
    ->getStorage($this->testEntityTypeName)
    ->create([
    'title' => $this->originalLabel,
    'type' => $this->referencedType
      ->id(),
    'description' => [
      'value' => $this
        ->randomMachineName(),
      'format' => 'basic_html',
    ],
    'langcode' => $this->baseLangcode,
  ]);
  $node
    ->save();
  $node
    ->addTranslation($this->translateToLangcode, [
    'title' => $this->translatedLabel,
  ]);
  $node
    ->save();
  return $node;
}