You are here

protected function TextimageTestBase::createTextField in Textimage 8.3

Same name and namespace in other branches
  1. 8.4 tests/src/Functional/TextimageTestBase.php \Drupal\Tests\textimage\Functional\TextimageTestBase::createTextField()

Create a new Text field for the Textimage formatter.

Parameters

string $name: The name of the new field (all lowercase), exclude the "field_" prefix.

string $bundle: The node type that this field will be added to.

array $storage_settings: A list of field storage settings that will be added to the defaults.

array $field_settings: A list of field settings that will be added to the field defaults.

array $widget_settings: A list of widget settings that will be added to the widget defaults.

3 calls to TextimageTestBase::createTextField()
TextimageFieldFormatterTest::testTextimageCaching in tests/src/Functional/TextimageFieldFormatterTest.php
Test Textimage caching.
TextimageFieldFormatterTest::testTextimageMultiValueTextFieldFormatter in tests/src/Functional/TextimageFieldFormatterTest.php
Test Textimage formatter on multi-value text fields.
TextimageFieldFormatterTest::testTextimageTextFieldFormatter in tests/src/Functional/TextimageFieldFormatterTest.php
Test Textimage formatter on node display and text field.

File

tests/src/Functional/TextimageTestBase.php, line 64

Class

TextimageTestBase
Base test class for Textimage tests.

Namespace

Drupal\Tests\textimage\Functional

Code

protected function createTextField($name, $bundle, array $storage_settings = [], array $field_settings = [], array $widget_settings = []) {
  FieldStorageConfig::create([
    'field_name' => $name,
    'entity_type' => 'node',
    'type' => 'text',
    'settings' => $storage_settings,
    'cardinality' => !empty($storage_settings['cardinality']) ? $storage_settings['cardinality'] : 1,
  ])
    ->save();
  $field_config = FieldConfig::create([
    'field_name' => $name,
    'label' => $name,
    'entity_type' => 'node',
    'bundle' => $bundle,
    'required' => !empty($field_settings['required']),
    'description' => !empty($field_settings['description']) ? $field_settings['description'] : '',
    'settings' => $field_settings,
  ])
    ->save();
  $this->entityDisplayRepository
    ->getFormDisplay('node', $bundle, 'default')
    ->setComponent($name, [
    'type' => 'text_textfield',
    'settings' => $widget_settings,
  ])
    ->save();
  $this->entityDisplayRepository
    ->getViewDisplay('node', $bundle, 'default')
    ->setComponent($name)
    ->save();
  return $field_config;
}