function FieldResolverTest::makeField

Same name in other branches
  1. 9 core/modules/jsonapi/tests/src/Kernel/Context/FieldResolverTest.php \Drupal\Tests\jsonapi\Kernel\Context\FieldResolverTest::makeField()
  2. 8.9.x core/modules/jsonapi/tests/src/Kernel/Context/FieldResolverTest.php \Drupal\Tests\jsonapi\Kernel\Context\FieldResolverTest::makeField()
  3. 11.x core/modules/jsonapi/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 core/modules/jsonapi/tests/src/Kernel/Context/FieldResolverTest.php

File

core/modules/jsonapi/tests/src/Kernel/Context/FieldResolverTest.php, line 379

Class

FieldResolverTest
@coversDefaultClass \Drupal\jsonapi\Context\FieldResolver @group jsonapi @group #slow

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();
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.