You are here

public static function BaseFieldDefinition::create in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Field/BaseFieldDefinition.php \Drupal\Core\Field\BaseFieldDefinition::create()
  2. 10 core/lib/Drupal/Core/Field/BaseFieldDefinition.php \Drupal\Core\Field\BaseFieldDefinition::create()

Creates a new field definition.

Parameters

string $type: The type of the field.

Return value

static A new field definition object.

Overrides ListDataDefinition::create

30 calls to BaseFieldDefinition::create()
BaseFieldDefinition::createFromItemType in core/lib/Drupal/Core/Field/BaseFieldDefinition.php
Creates a new list data definition for items of the given data type.
BaseFieldDefinitionTest::testCustomStorage in core/tests/Drupal/Tests/Core/Entity/BaseFieldDefinitionTest.php
Tests custom storage.
BaseFieldDefinitionTest::testDefaultFieldSettings in core/tests/Drupal/Tests/Core/Entity/BaseFieldDefinitionTest.php
Tests the initialization of default field settings.
BaseFieldDefinitionTest::testDefaultValueCallback in core/tests/Drupal/Tests/Core/Entity/BaseFieldDefinitionTest.php
Tests default value callbacks.
BaseFieldDefinitionTest::testFieldCardinality in core/tests/Drupal/Tests/Core/Entity/BaseFieldDefinitionTest.php
Tests field cardinality.

... See full list

1 method overrides BaseFieldDefinition::create()
BaseFieldDefinitionTest::create in core/modules/migrate/tests/src/Unit/Plugin/migrate/destination/EntityTestBase.php
Creates a new field definition.

File

core/lib/Drupal/Core/Field/BaseFieldDefinition.php, line 57

Class

BaseFieldDefinition
A class for defining entity fields.

Namespace

Drupal\Core\Field

Code

public static function create($type) {
  $field_definition = new static([]);
  $field_definition->type = $type;
  $field_definition->itemDefinition = FieldItemDataDefinition::create($field_definition);

  // Create a definition for the items, and initialize it with the default
  // settings for the field type.
  $field_type_manager = \Drupal::service('plugin.manager.field.field_type');
  $default_settings = $field_type_manager
    ->getDefaultStorageSettings($type) + $field_type_manager
    ->getDefaultFieldSettings($type);
  $field_definition->itemDefinition
    ->setSettings($default_settings);
  return $field_definition;
}