function JsonapiKernelTestBase::createTextField

Same name and namespace in other branches
  1. 9 core/modules/jsonapi/tests/src/Kernel/JsonapiKernelTestBase.php \Drupal\Tests\jsonapi\Kernel\JsonapiKernelTestBase::createTextField()
  2. 10 core/modules/jsonapi/tests/src/Kernel/JsonapiKernelTestBase.php \Drupal\Tests\jsonapi\Kernel\JsonapiKernelTestBase::createTextField()
  3. 11.x core/modules/jsonapi/tests/src/Kernel/JsonapiKernelTestBase.php \Drupal\Tests\jsonapi\Kernel\JsonapiKernelTestBase::createTextField()

Creates a field of an entity reference field storage on the bundle.

Parameters

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

string $bundle: The bundle name of the entity the field will be attached to.

string $field_name: The name of the field; if it exists, a new instance of the existing. field will be created.

string $field_label: The label of the field.

int $cardinality: The cardinality of the field.

See also

\Drupal\Core\Entity\Plugin\EntityReferenceSelection\SelectionBase::buildConfigurationForm()

3 calls to JsonapiKernelTestBase::createTextField()
FilterTest::savePaintingType in core/modules/jsonapi/tests/src/Kernel/Query/FilterTest.php
Creates a painting node type.
JsonApiDocumentTopLevelNormalizerTest::setUp in core/modules/jsonapi/tests/src/Kernel/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php
SerializerTest::setUp in core/modules/jsonapi/tests/src/Kernel/Serializer/SerializerTest.php

File

core/modules/jsonapi/tests/src/Kernel/JsonapiKernelTestBase.php, line 89

Class

JsonapiKernelTestBase
Contains shared test utility methods.

Namespace

Drupal\Tests\jsonapi\Kernel

Code

protected function createTextField($entity_type, $bundle, $field_name, $field_label, $cardinality = 1) {
    // Look for or add the specified field to the requested entity bundle.
    if (!FieldStorageConfig::loadByName($entity_type, $field_name)) {
        FieldStorageConfig::create([
            'field_name' => $field_name,
            'type' => 'text',
            'entity_type' => $entity_type,
            'cardinality' => $cardinality,
        ])->save();
    }
    if (!FieldConfig::loadByName($entity_type, $bundle, $field_name)) {
        FieldConfig::create([
            'field_name' => $field_name,
            'entity_type' => $entity_type,
            'bundle' => $bundle,
            'label' => $field_label,
        ])->save();
    }
}

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