function FileFieldCreationTrait::createFileField

Same name in other branches
  1. 9 core/modules/file/tests/src/Functional/FileFieldCreationTrait.php \Drupal\Tests\file\Functional\FileFieldCreationTrait::createFileField()
  2. 10 core/modules/file/tests/src/Functional/FileFieldCreationTrait.php \Drupal\Tests\file\Functional\FileFieldCreationTrait::createFileField()
  3. 11.x core/modules/file/tests/src/Functional/FileFieldCreationTrait.php \Drupal\Tests\file\Functional\FileFieldCreationTrait::createFileField()

Creates a new file field.

Parameters

string $name: The name of the new field (all lowercase), exclude the "field_" prefix.

string $entity_type: The entity type.

string $bundle: The bundle that this field will be added to.

array $storage_settings: A list of field storage settings that will be added to the defaults.

array $field_settings: A list of instance settings that will be added to the instance defaults.

array $widget_settings: A list of widget settings that will be added to the widget defaults.

Return value

\Drupal\field\FieldStorageConfigInterface The file field.

35 calls to FileFieldCreationTrait::createFileField()
DrupalSelenium2DriverTest::setUp in core/tests/Drupal/FunctionalJavascriptTests/Tests/DrupalSelenium2DriverTest.php
FileFieldAnonymousSubmissionTest::doTestNodeWithFileWithoutTitle in core/modules/file/tests/src/Functional/FileFieldAnonymousSubmissionTest.php
Helper method to test file submissions with missing node titles.
FileFieldAnonymousSubmissionTest::testAnonymousNodeWithFile in core/modules/file/tests/src/Functional/FileFieldAnonymousSubmissionTest.php
Tests file submission for an anonymous visitor.
FileFieldAttributesTest::setUp in core/modules/rdf/tests/src/Functional/FileFieldAttributesTest.php
FileFieldDisplayTest::testDefaultFileFieldDisplay in core/modules/file/tests/src/Functional/FileFieldDisplayTest.php
Tests default display of File Field.

... See full list

File

core/modules/file/tests/src/Functional/FileFieldCreationTrait.php, line 32

Class

FileFieldCreationTrait
Provides methods for creating file fields.

Namespace

Drupal\Tests\file\Functional

Code

public function createFileField($name, $entity_type, $bundle, $storage_settings = [], $field_settings = [], $widget_settings = []) {
    $field_storage = FieldStorageConfig::create([
        'entity_type' => $entity_type,
        'field_name' => $name,
        'type' => 'file',
        'settings' => $storage_settings,
        'cardinality' => !empty($storage_settings['cardinality']) ? $storage_settings['cardinality'] : 1,
    ]);
    $field_storage->save();
    $this->attachFileField($name, $entity_type, $bundle, $field_settings, $widget_settings);
    return $field_storage;
}

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