You are here

public function NameTestTrait::createNameField in Name Field 8

Creates a name field with default settings.

Parameters

string $field_name: The field name.

string $entity_type: The entity type.

string $bundle: The bundle.

array $storage_extras: Additional field storage settings.

  • cardinality (int)
  • settings (array)

array $field_extras: Additional field settings.

  • widget: ['type' => 'options_buttons']
  • settings (array)

Return value

\Drupal\Core\Field\FieldDefinitionInterface The field definition.

4 calls to NameTestTrait::createNameField()
NameAutocompleteTest::setUp in tests/src/Kernel/NameAutocompleteTest.php
NameNodeTokenReplaceTest::setUp in tests/src/Functional/NameNodeTokenReplaceTest.php
NameOptionsProviderTest::testTitleOptionsFromField in tests/src/Functional/NameOptionsProviderTest.php
Tests the field options.
NameOptionsProviderTest::testTitleOptionsFromTaxonomy in tests/src/Functional/NameOptionsProviderTest.php
Tests the taxonomy options source.

File

tests/src/Functional/NameTestTrait.php, line 34

Class

NameTestTrait
Common testing traits.

Namespace

Drupal\Tests\name\Functional

Code

public function createNameField($field_name, $entity_type, $bundle, array $storage_extras = [], array $field_extras = []) {
  FieldStorageConfig::create([
    'field_name' => $field_name,
    'entity_type' => $entity_type,
    'type' => 'name',
  ] + $storage_extras)
    ->save();
  $field_config = FieldConfig::create([
    'field_name' => $field_name,
    'entity_type' => $entity_type,
    'type' => 'name',
    'bundle' => $bundle,
  ] + $field_extras);
  $field_config
    ->save();
  return $field_config;
}