public static BaseFieldDefinition::create($type)
Creates a new field definition.
Parameters
string $type: The type of the field.
Return value
static A new field definition object.
Overrides ListDataDefinition::create
File
- core/lib/Drupal/Core/Field/BaseFieldDefinition.php, line 56
Class
- BaseFieldDefinition
- A class for defining entity fields.
Namespace
Drupal\Core\Field
Code
public static function create($type) { $field_definition = new static(array()); $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. // @todo Cleanup in https://www.drupal.org/node/2116341. $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; }
Please login to continue.