You are here

protected function ContactStorageExportServiceKernelTest::addField in Contact Storage Export 8

A helper function that adds a field to the contact message entity.

Parameters

string $name: A field name.

string $type: A field type.

string $bundle: A bundle.

array $storage_configuration: (optional) Field storage configuration.

array $instance_configuration: (optional) Field instance configuration.

Throws

\Drupal\Core\Entity\EntityStorageException

1 call to ContactStorageExportServiceKernelTest::addField()
ContactStorageExportServiceKernelTest::testContactStorageExport in tests/src/Kernel/ContactStorageExportServiceKernelTest.php
Tests contact storage export.

File

tests/src/Kernel/ContactStorageExportServiceKernelTest.php, line 142

Class

ContactStorageExportServiceKernelTest
Tests contact storage export service methods.

Namespace

Drupal\Tests\contact_storage_export\Kernel

Code

protected function addField($name, $type, $bundle, array $storage_configuration = [], array $instance_configuration = []) {
  $field_storage = FieldStorageConfig::create([
    'field_name' => $name,
    'entity_type' => 'contact_message',
    'type' => $type,
  ] + $storage_configuration);
  $field_storage
    ->save();
  $field_instance = FieldConfig::create([
    'field_storage' => $field_storage,
    'bundle' => $bundle,
    'label' => $name,
  ] + $instance_configuration);
  $field_instance
    ->save();
}