You are here

protected function EntityReferenceFieldTranslatedReferenceViewTest::createReferrerEntity in Drupal 9

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

Create the referrer entity.

1 call to EntityReferenceFieldTranslatedReferenceViewTest::createReferrerEntity()
EntityReferenceFieldTranslatedReferenceViewTest::testEntityReferenceDisplay in core/modules/field/tests/src/Functional/EntityReference/EntityReferenceFieldTranslatedReferenceViewTest.php
Tests if the entity is displayed in an entity reference field.

File

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

Class

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

Namespace

Drupal\Tests\field\Functional\EntityReference

Code

protected function createReferrerEntity($translatable = TRUE) {

  /** @var \Drupal\node\Entity\Node $node */
  $node = \Drupal::entityTypeManager()
    ->getStorage($this->testEntityTypeName)
    ->create([
    'title' => $this
      ->randomMachineName(),
    'type' => $this->referrerType
      ->id(),
    'description' => [
      'value' => $this
        ->randomMachineName(),
      'format' => 'basic_html',
    ],
    $this->referenceFieldName => [
      [
        'target_id' => $this->referencedEntityWithTranslation
          ->id(),
      ],
      [
        'target_id' => $this->referencedEntityWithoutTranslation
          ->id(),
      ],
    ],
    'langcode' => $this->baseLangcode,
  ]);
  if ($translatable) {
    $node
      ->addTranslation($this->translateToLangcode, $node
      ->toArray());
  }
  $node
    ->save();
  return $node;
}