You are here

protected function TaxonomyTranslationTestTrait::setUpTermReferenceField in Drupal 8

Same name in this branch
  1. 8 core/modules/taxonomy/src/Tests/TaxonomyTranslationTestTrait.php \Drupal\taxonomy\Tests\TaxonomyTranslationTestTrait::setUpTermReferenceField()
  2. 8 core/modules/taxonomy/tests/src/Functional/TaxonomyTranslationTestTrait.php \Drupal\Tests\taxonomy\Functional\TaxonomyTranslationTestTrait::setUpTermReferenceField()
Same name and namespace in other branches
  1. 9 core/modules/taxonomy/tests/src/Functional/TaxonomyTranslationTestTrait.php \Drupal\Tests\taxonomy\Functional\TaxonomyTranslationTestTrait::setUpTermReferenceField()

Adds term reference field for the article content type.

2 calls to TaxonomyTranslationTestTrait::setUpTermReferenceField()
TermTranslationFieldViewTest::setUp in core/modules/taxonomy/tests/src/Functional/TermTranslationFieldViewTest.php
TermTranslationTest::setUp in core/modules/taxonomy/tests/src/Functional/TermTranslationTest.php

File

core/modules/taxonomy/tests/src/Functional/TaxonomyTranslationTestTrait.php, line 73

Class

TaxonomyTranslationTestTrait
Provides common testing base for translated taxonomy terms.

Namespace

Drupal\Tests\taxonomy\Functional

Code

protected function setUpTermReferenceField() {
  $handler_settings = [
    'target_bundles' => [
      $this->vocabulary
        ->id() => $this->vocabulary
        ->id(),
    ],
    'auto_create' => TRUE,
  ];
  $this
    ->createEntityReferenceField('node', 'article', $this->termFieldName, NULL, 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
  $field_storage = FieldStorageConfig::loadByName('node', $this->termFieldName);
  $field_storage
    ->setTranslatable(FALSE);
  $field_storage
    ->save();

  /** @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $display_repository */
  $display_repository = \Drupal::service('entity_display.repository');
  $display_repository
    ->getFormDisplay('node', 'article')
    ->setComponent($this->termFieldName, [
    'type' => 'entity_reference_autocomplete_tags',
  ])
    ->save();
  $display_repository
    ->getViewDisplay('node', 'article')
    ->setComponent($this->termFieldName, [
    'type' => 'entity_reference_label',
  ])
    ->save();
}