W3cubDocs

/Drupal 8

public static function BaseFieldDefinition::create

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;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Field!BaseFieldDefinition.php/function/BaseFieldDefinition::create/8.1.x