You are here

protected function EntityReferenceFieldTranslatedReferenceViewTest::setUpEntityReferenceField in Drupal 8

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

Adds term reference field for the article content type.

1 call to EntityReferenceFieldTranslatedReferenceViewTest::setUpEntityReferenceField()
EntityReferenceFieldTranslatedReferenceViewTest::setUp in core/modules/field/tests/src/Functional/EntityReference/EntityReferenceFieldTranslatedReferenceViewTest.php

File

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

Class

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

Namespace

Drupal\Tests\field\Functional\EntityReference

Code

protected function setUpEntityReferenceField() {
  FieldStorageConfig::create([
    'field_name' => $this->referenceFieldName,
    'entity_type' => $this->testEntityTypeName,
    'type' => 'entity_reference',
    'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
    'translatable' => $this->translatable,
    'settings' => [
      'allowed_values' => [
        [
          'target_type' => $this->testEntityTypeName,
        ],
      ],
    ],
  ])
    ->save();
  FieldConfig::create([
    'field_name' => $this->referenceFieldName,
    'bundle' => $this->referrerType
      ->id(),
    'entity_type' => $this->testEntityTypeName,
  ])
    ->save();

  /** @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $display_repository */
  $display_repository = \Drupal::service('entity_display.repository');
  $display_repository
    ->getFormDisplay($this->testEntityTypeName, $this->referrerType
    ->id())
    ->setComponent($this->referenceFieldName, [
    'type' => 'entity_reference_autocomplete',
  ])
    ->save();
  $display_repository
    ->getViewDisplay($this->testEntityTypeName, $this->referrerType
    ->id())
    ->setComponent($this->referenceFieldName, [
    'type' => 'entity_reference_label',
  ])
    ->save();
}