You are here

protected function FieldResolverTest::makeField in JSON:API 8.2

Same name and namespace in other branches
  1. 8 tests/src/Kernel/Context/FieldResolverTest.php \Drupal\Tests\jsonapi\Kernel\Context\FieldResolverTest::makeField()

Creates a field for a specified entity type/bundle.

Parameters

string $type: The field type.

string $name: The name of the field to create.

string $entity_type: The entity type to which the field will be attached.

string[] $bundles: The entity bundles to which the field will be attached.

array $storage_settings: Custom storage settings for the field.

array $config_settings: Custom configuration settings for the field.

1 call to FieldResolverTest::makeField()
FieldResolverTest::setUp in tests/src/Kernel/Context/FieldResolverTest.php

File

tests/src/Kernel/Context/FieldResolverTest.php, line 365

Class

FieldResolverTest
@coversDefaultClass \Drupal\jsonapi\Context\FieldResolver @group jsonapi @group legacy

Namespace

Drupal\Tests\jsonapi\Kernel\Context

Code

protected function makeField($type, $name, $entity_type, array $bundles, array $storage_settings = [], array $config_settings = []) {
  $storage_config = [
    'field_name' => $name,
    'type' => $type,
    'entity_type' => $entity_type,
    'settings' => $storage_settings,
  ];
  FieldStorageConfig::create($storage_config)
    ->save();
  foreach ($bundles as $bundle) {
    FieldConfig::create([
      'field_name' => $name,
      'entity_type' => $entity_type,
      'bundle' => $bundle,
      'settings' => $config_settings,
    ])
      ->save();
  }
}