You are here

protected function FormatterTestBase::createField in Address 8

Creates an entity_test field of the given type.

Parameters

string $field_type: The field type.

string $formatter_id: The formatter ID.

3 calls to FormatterTestBase::createField()
AddressDefaultFormatterTest::setUp in tests/src/Kernel/Formatter/AddressDefaultFormatterTest.php
AddressPlainFormatterTest::setUp in tests/src/Kernel/Formatter/AddressPlainFormatterTest.php
CountryDefaultFormatterTest::setUp in tests/src/Kernel/Formatter/CountryDefaultFormatterTest.php

File

tests/src/Kernel/Formatter/FormatterTestBase.php, line 69

Class

FormatterTestBase
Provides a base test for kernel formatter tests.

Namespace

Drupal\Tests\address\Kernel\Formatter

Code

protected function createField($field_type, $formatter_id) {
  $field_storage = FieldStorageConfig::create([
    'field_name' => $this->fieldName,
    'entity_type' => 'entity_test',
    'type' => $field_type,
  ]);
  $field_storage
    ->save();
  $field = FieldConfig::create([
    'field_storage' => $field_storage,
    'bundle' => 'entity_test',
    'label' => $this
      ->randomMachineName(),
  ]);
  $field
    ->save();
  $this->display = \Drupal::service('entity_display.repository')
    ->getViewDisplay('entity_test', 'entity_test', 'default');
  $this->display
    ->setComponent($this->fieldName, [
    'type' => $formatter_id,
    'settings' => [],
  ]);
  $this->display
    ->save();
}