You are here

protected function EntityReferenceFieldTranslatedReferenceViewTest::createReferrerEntity in Zircon Profile 8

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

Create the referrer entity.

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

File

core/modules/field/src/Tests/EntityReference/EntityReferenceFieldTranslatedReferenceViewTest.php, line 302
Contains \Drupal\field\Tests\EntityReference\EntityReferenceFieldTranslatedReferenceViewTest.

Class

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

Namespace

Drupal\field\Tests\EntityReference

Code

protected function createReferrerEntity($translatable = TRUE) {

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