function FieldTypePluginManager::createInstance

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Field/FieldTypePluginManager.php \Drupal\Core\Field\FieldTypePluginManager::createInstance()
  2. 10 core/lib/Drupal/Core/Field/FieldTypePluginManager.php \Drupal\Core\Field\FieldTypePluginManager::createInstance()
  3. 11.x core/lib/Drupal/Core/Field/FieldTypePluginManager.php \Drupal\Core\Field\FieldTypePluginManager::createInstance()

Creates a field item, which is not part of an entity or field item list.

Parameters

string $field_type: The field type, for which a field item should be created.

array $configuration: The plugin configuration array, i.e. an array with the following keys:

Return value

\Drupal\Core\Field\FieldItemInterface The instantiated object.

Overrides PluginManagerBase::createInstance

File

core/lib/Drupal/Core/Field/FieldTypePluginManager.php, line 64

Class

FieldTypePluginManager
Plugin manager for 'field type' plugins.

Namespace

Drupal\Core\Field

Code

public function createInstance($field_type, array $configuration = []) {
    $configuration['data_definition'] = $configuration['field_definition']->getItemDefinition();
    return $this->typedDataManager
        ->createInstance("field_item:{$field_type}", $configuration);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.