FieldItemDataDefinition::createFromDataType

public static FieldItemDataDefinition::createFromDataType($data_type)

Creates a new data definition object.

This method is typically used by \Drupal\Core\TypedData\TypedDataManager::createDataDefinition() to build a definition object for an arbitrary data type. When the definition class is known, it is recommended to directly use the static create() method on that class instead; e.g.:

  $map_definition = \Drupal\Core\TypedData\MapDataDefinition::create();

Parameters

string $data_type: The data type, for which a data definition should be created.

Return value

static

Throws

\InvalidArgumentException If an unsupported data type gets passed to the class; e.g., 'string' to a definition class handling 'entity:* data types.

Overrides DataDefinition::createFromDataType

File

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

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();
}
doc_Drupal
2016-10-29 09:11:42
Comments
Leave a Comment

Please login to continue.