function QuickEditTestBase::createFieldWithStorage

Same name in other branches
  1. 8.9.x core/modules/quickedit/tests/src/Kernel/QuickEditTestBase.php \Drupal\Tests\quickedit\Kernel\QuickEditTestBase::createFieldWithStorage()

Creates a field.

Parameters

string $field_name: The field name.

string $type: The field type.

int $cardinality: The field's cardinality.

string $label: The field's label (used everywhere: widget label, formatter label).

array $field_settings: The field's settings.

string $widget_type: The widget type.

array $widget_settings: The widget settings.

string $formatter_type: The formatter type.

array $formatter_settings: The formatter settings.

6 calls to QuickEditTestBase::createFieldWithStorage()
EditorIntegrationTest::setUp in core/modules/quickedit/tests/src/Kernel/EditorIntegrationTest.php
Sets the default field storage backend for fields created during tests.
EditorSelectionTest::testNumber in core/modules/quickedit/tests/src/Kernel/EditorSelectionTest.php
Tests a number field, with cardinality 1 and >1.
EditorSelectionTest::testText in core/modules/quickedit/tests/src/Kernel/EditorSelectionTest.php
Tests a string (plain text) field, with cardinality 1 and >1.
EditorSelectionTest::testTextWysiwyg in core/modules/quickedit/tests/src/Kernel/EditorSelectionTest.php
Tests a textual field with varying text format compatibility.
MetadataGeneratorTest::testEditorWithCustomMetadata in core/modules/quickedit/tests/src/Kernel/MetadataGeneratorTest.php
Tests a field whose associated in-place editor generates custom metadata.

... See full list

File

core/modules/quickedit/tests/src/Kernel/QuickEditTestBase.php, line 78

Class

QuickEditTestBase
Base class for testing Quick Edit functionality.

Namespace

Drupal\Tests\quickedit\Kernel

Code

protected function createFieldWithStorage($field_name, $type, $cardinality, $label, $field_settings, $widget_type, $widget_settings, $formatter_type, $formatter_settings) {
    $field_storage = $field_name . '_field_storage';
    $this->fields->{$field_storage} = FieldStorageConfig::create([
        'field_name' => $field_name,
        'entity_type' => 'entity_test',
        'type' => $type,
        'cardinality' => $cardinality,
    ]);
    $this->fields->{$field_storage}
        ->save();
    $field = $field_name . '_field';
    $this->fields->{$field} = FieldConfig::create([
        'field_storage' => $this->fields->{$field_storage},
        'bundle' => 'entity_test',
        'label' => $label,
        'description' => $label,
        'weight' => mt_rand(0, 127),
        'settings' => $field_settings,
    ]);
    $this->fields->{$field}
        ->save();
    
    /** @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $display_repository */
    $display_repository = \Drupal::service('entity_display.repository');
    $display_repository->getFormDisplay('entity_test', 'entity_test')
        ->setComponent($field_name, [
        'type' => $widget_type,
        'settings' => $widget_settings,
    ])
        ->save();
    $display_repository->getViewDisplay('entity_test', 'entity_test')
        ->setComponent($field_name, [
        'label' => 'above',
        'type' => $formatter_type,
        'settings' => $formatter_settings,
    ])
        ->save();
}

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