You are here

protected function LengthIndicatorTest::createField in Length Indicator 8

Creates a field on the entity_test entity type.

Parameters

string $field_type: The field type.

string $widget_type: The widget type.

1 call to LengthIndicatorTest::createField()
LengthIndicatorTest::setUp in tests/src/FunctionalJavascript/LengthIndicatorTest.php

File

tests/src/FunctionalJavascript/LengthIndicatorTest.php, line 57

Class

LengthIndicatorTest
Tests the UI for entity displays.

Namespace

Drupal\Tests\length_indicator\FunctionalJavascript

Code

protected function createField($field_type, $widget_type) {

  // Use the field type as a name to make things simple.
  $field_name = $field_type;
  $field_storage = FieldStorageConfig::create([
    'field_name' => $field_name,
    'entity_type' => 'entity_test',
    'type' => $field_type,
  ]);
  $field_storage
    ->save();
  FieldConfig::create([
    'field_storage' => $field_storage,
    'bundle' => 'entity_test',
    'label' => $this
      ->randomMachineName() . '_label',
  ])
    ->save();
  EntityFormDisplay::load('entity_test.entity_test.default')
    ->setComponent($field_name, [
    'type' => $widget_type,
    'settings' => [
      'placeholder' => 'A placeholder on ' . $widget_type,
    ],
  ])
    ->save();
}