function FieldItemDataDefinition::createFromDataType

Same name in other branches
  1. 9 core/lib/Drupal/Core/Field/TypedData/FieldItemDataDefinition.php \Drupal\Core\Field\TypedData\FieldItemDataDefinition::createFromDataType()
  2. 8.9.x core/lib/Drupal/Core/Field/TypedData/FieldItemDataDefinition.php \Drupal\Core\Field\TypedData\FieldItemDataDefinition::createFromDataType()
  3. 10 core/lib/Drupal/Core/Field/TypedData/FieldItemDataDefinition.php \Drupal\Core\Field\TypedData\FieldItemDataDefinition::createFromDataType()

Overrides DataDefinition::createFromDataType

File

core/lib/Drupal/Core/Field/TypedData/FieldItemDataDefinition.php, line 28

Class

FieldItemDataDefinition
A typed data definition class for defining field items.

Namespace

Drupal\Core\Field\TypedData

Code

public static function createFromDataType($data_type) {
    // The data type of a field item is in the form of "field_item:$field_type".
    $parts = explode(':', $data_type, 2);
    if ($parts[0] != 'field_item') {
        throw new \InvalidArgumentException('Data type must be in the form of "field_item:FIELD_TYPE".');
    }
    $field_definition = BaseFieldDefinition::create($parts[1]);
    return $field_definition->getItemDefinition();
}

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