public static function EntityRevisionDataDefinition::createFromDataType in Entity Reference Revisions 8
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 EntityDataDefinition::createFromDataType
File
- src/
TypedData/ EntityRevisionDataDefinition.php, line 16
Class
- EntityRevisionDataDefinition
- A typed data definition class for describing entities.
Namespace
Drupal\entity_reference_revisions\TypedDataCode
public static function createFromDataType($data_type) {
$parts = explode(':', $data_type);
if ($parts[0] != 'entity_revision') {
throw new \InvalidArgumentException('Data type must be in the form of "entity_revision:ENTITY_TYPE:BUNDLE."');
}
$definition = static::create();
// Set the passed entity type and bundle.
if (isset($parts[1])) {
$definition
->setEntityTypeId($parts[1]);
}
if (isset($parts[2])) {
$definition
->setBundles(array(
$parts[2],
));
}
return $definition;
}