You are here

protected function DiffPluginVariousTest::addArticleTextField in Diff 8

Adds a text field.

Parameters

string $field_name: The machine field name.

string $label: The field label.

string $field_type: The field type.

string $widget_type: The widget type.

1 call to DiffPluginVariousTest::addArticleTextField()
DiffPluginVariousTest::testTextPlugin in tests/src/Functional/DiffPluginVariousTest.php
Tests the Text plugin.

File

tests/src/Functional/DiffPluginVariousTest.php, line 40

Class

DiffPluginVariousTest
Tests the Diff module plugins.

Namespace

Drupal\Tests\diff\Functional

Code

protected function addArticleTextField($field_name, $label, $field_type, $widget_type) {

  // Create a field.
  $field_storage = FieldStorageConfig::create([
    'field_name' => $field_name,
    'entity_type' => 'node',
    'type' => $field_type,
  ]);
  $field_storage
    ->save();
  FieldConfig::create([
    'field_storage' => $field_storage,
    'bundle' => 'article',
    'label' => $label,
  ])
    ->save();
  $this->formDisplay
    ->load('node.article.default')
    ->setComponent($field_name, [
    'type' => $widget_type,
  ])
    ->save();
  $this->viewDisplay
    ->load('node.article.default')
    ->setComponent($field_name)
    ->save();
}