function HandlerFieldFieldTest::createFields

Same name and namespace in other branches
  1. 9 core/modules/field/tests/src/Kernel/Views/HandlerFieldFieldTest.php \Drupal\Tests\field\Kernel\Views\HandlerFieldFieldTest::createFields()
  2. 8.9.x core/modules/field/tests/src/Kernel/Views/HandlerFieldFieldTest.php \Drupal\Tests\field\Kernel\Views\HandlerFieldFieldTest::createFields()
  3. 10 core/modules/field/tests/src/Kernel/Views/HandlerFieldFieldTest.php \Drupal\Tests\field\Kernel\Views\HandlerFieldFieldTest::createFields()

Creates the testing fields.

1 call to HandlerFieldFieldTest::createFields()
HandlerFieldFieldTest::testFieldRender in core/modules/field/tests/src/Kernel/Views/HandlerFieldFieldTest.php
Tests fields rendering in views.

File

core/modules/field/tests/src/Kernel/Views/HandlerFieldFieldTest.php, line 330

Class

HandlerFieldFieldTest
Tests the field rendering in views.

Namespace

Drupal\Tests\field\Kernel\Views

Code

protected function createFields() {
    $fields_data = [
        [
            'field_name' => 'field_name_0',
            'type' => 'string',
        ],
        [
            'field_name' => 'field_name_1',
            'type' => 'string',
        ],
        [
            'field_name' => 'field_name_2',
            'type' => 'string',
        ],
        // Field with cardinality > 1.
[
            'field_name' => 'field_name_3',
            'type' => 'string',
            'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
        ],
        // Field that will have no value.
[
            'field_name' => 'field_name_4',
            'type' => 'string',
            'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
        ],
        // Text field.
[
            'field_name' => 'field_name_5',
            'type' => 'text',
        ],
        // Text field with access control.
        // @see field_test_entity_field_access()
[
            'field_name' => 'field_no_view_access',
            'type' => 'text',
        ],
    ];
    foreach ($fields_data as $field_data) {
        $field_data += [
            'entity_type' => 'node',
        ];
        $field_storage = FieldStorageConfig::create($field_data);
        $field_storage->save();
        $this->fieldStorages[] = $field_storage;
        FieldConfig::create([
            'field_storage' => $field_storage,
            'bundle' => 'page',
        ])->save();
    }
}

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