You are here

protected function FieldDefinitionTest::initializeFieldUsingFactory in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Entity/FieldDefinitionTest.php \Drupal\Tests\Core\Entity\FieldDefinitionTest::initializeFieldUsingFactory()

Creates a bundle field using a specified factory.

Parameters

string $factory_name: The factory name to use.

Return value

\Drupal\Core\Field\FieldDefinition

14 calls to FieldDefinitionTest::initializeFieldUsingFactory()
FieldDefinitionTest::testBundle in core/tests/Drupal/Tests/Core/Entity/FieldDefinitionTest.php
@covers ::setTargetBundle @covers ::getTargetBundle @dataProvider factoryTypeProvider
FieldDefinitionTest::testDefaultFieldSettings in core/tests/Drupal/Tests/Core/Entity/FieldDefinitionTest.php
@covers ::getSetting @covers ::setSetting @covers ::getSettings @dataProvider factoryTypeProvider
FieldDefinitionTest::testDefaultValueCallback in core/tests/Drupal/Tests/Core/Entity/FieldDefinitionTest.php
Tests default value callbacks.
FieldDefinitionTest::testDisplayConfigurationSettings in core/tests/Drupal/Tests/Core/Entity/FieldDefinitionTest.php
Tests the display configuration settings.
FieldDefinitionTest::testFieldDefaultValue in core/tests/Drupal/Tests/Core/Entity/FieldDefinitionTest.php
@covers ::getDefaultValue @covers ::setDefaultValue @dataProvider factoryTypeProvider

... See full list

File

core/tests/Drupal/Tests/Core/Entity/FieldDefinitionTest.php, line 368

Class

FieldDefinitionTest
Unit test for the FieldDefinition class.

Namespace

Drupal\Tests\Core\Entity

Code

protected function initializeFieldUsingFactory($factory_name) {
  switch ($factory_name) {
    case 'createFromFieldStorageDefinition':
      return FieldDefinition::createFromFieldStorageDefinition($this->storageDefinition);
    case 'create':
      $definition = FieldDefinition::create($this->fieldType);
      $definition
        ->setFieldStorageDefinition($this->storageDefinition);
      return $definition;
    case 'createFromDataType':
      $definition = FieldDefinition::createFromDataType($this->fieldType);
      $definition
        ->setFieldStorageDefinition($this->storageDefinition);
      return $definition;
    case 'createFromItemType':
      $definition = FieldDefinition::createFromItemType($this->fieldType);
      $definition
        ->setFieldStorageDefinition($this->storageDefinition);
      return $definition;
  }
}