function 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
3 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.
- FieldItemDataDefinition::createFromDataType in core/
lib/ Drupal/ Core/ Field/ TypedData/ FieldItemDataDefinition.php - Creates a new data definition object.
- Sql::getFieldSchema in core/
modules/ migrate/ src/ Plugin/ migrate/ id_map/ Sql.php - Creates schema from an ID definition.
File
-
core/
lib/ Drupal/ Core/ Field/ BaseFieldDefinition.php, line 57
Class
- BaseFieldDefinition
- A class for defining entity fields.
Namespace
Drupal\Core\FieldCode
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;
}