You are here

protected function TaxonomyTranslationTestTrait::setUpTermReferenceField in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/taxonomy/src/Tests/TaxonomyTranslationTestTrait.php \Drupal\taxonomy\Tests\TaxonomyTranslationTestTrait::setUpTermReferenceField()

Adds term reference field for the article content type.

Parameters

bool $translatable: (optional) If TRUE, create a translatable term reference field. Defaults to FALSE.

2 calls to TaxonomyTranslationTestTrait::setUpTermReferenceField()
TermTranslationBreadcrumbTest::setUp in core/modules/taxonomy/src/Tests/TermTranslationBreadcrumbTest.php
Sets up a Drupal site for running functional and integration tests.
TermTranslationFieldViewTest::setUp in core/modules/taxonomy/src/Tests/TermTranslationFieldViewTest.php
Sets up a Drupal site for running functional and integration tests.

File

core/modules/taxonomy/src/Tests/TaxonomyTranslationTestTrait.php, line 86
Contains \Drupal\taxonomy\Tests\TaxonomyTranslationTestTrait.

Class

TaxonomyTranslationTestTrait
Provides common testing base for translated taxonomy terms.

Namespace

Drupal\taxonomy\Tests

Code

protected function setUpTermReferenceField() {
  $handler_settings = array(
    'target_bundles' => array(
      $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();
  entity_get_form_display('node', 'article', 'default')
    ->setComponent($this->termFieldName, array(
    'type' => 'entity_reference_autocomplete_tags',
  ))
    ->save();
  entity_get_display('node', 'article', 'default')
    ->setComponent($this->termFieldName, array(
    'type' => 'entity_reference_label',
  ))
    ->save();
}