You are here

protected function TaxonomyEntityIndexKernelTestBase::setupTermField in Taxonomy Entity Index 8

Creates a new entity reference field for the given bundle.

Parameters

string $entity_type_id: Entity type to add the field to.

string $bundle: Bundle of field.

string $field_name: Field name.

3 calls to TaxonomyEntityIndexKernelTestBase::setupTermField()
TaxonomyEntityIndexEntityTest::setUp in tests/src/Kernel/TaxonomyEntityIndexEntityTest.php
TaxonomyEntityIndexFieldNamesTest::testFieldNamesUpdate in tests/src/Kernel/TaxonomyEntityIndexFieldNamesTest.php
Tests caching in taxonomy_entity_index_get_taxonomy_field_names().
TaxonomyEntityIndexKernelTestBase::setUp in tests/src/Kernel/TaxonomyEntityIndexKernelTestBase.php

File

tests/src/Kernel/TaxonomyEntityIndexKernelTestBase.php, line 80

Class

TaxonomyEntityIndexKernelTestBase
Defines a base class for taxonomy entity index kernel tests.

Namespace

Drupal\Tests\taxonomy_entity_index\Kernel

Code

protected function setupTermField($entity_type_id, $bundle, $field_name) {
  if (!FieldStorageConfig::load("{$entity_type_id}.{$field_name}")) {
    $storage = FieldStorageConfig::create([
      'entity_type' => $entity_type_id,
      'field_name' => $field_name,
      'id' => "{$entity_type_id}.{$field_name}",
      'type' => 'entity_reference',
      'settings' => [
        'target_type' => 'taxonomy_term',
      ],
    ]);
    $storage
      ->save();
  }
  if (!FieldConfig::load("{$entity_type_id}.{$bundle}.{$field_name}")) {
    $config = FieldConfig::create([
      'field_name' => $field_name,
      'entity_type' => $entity_type_id,
      'bundle' => $bundle,
      'id' => "{$entity_type_id}.{$bundle}.{$field_name}",
      'label' => Unicode::ucfirst($field_name),
    ]);
    $config
      ->save();
  }
}