private function StaticDataDefinitionExtractor::createDataDefinition in JSON:API Schema 8
1 call to StaticDataDefinitionExtractor::createDataDefinition()
File
- src/
StaticDataDefinitionExtractor.php, line 134
Class
- StaticDataDefinitionExtractor
- Extracts the data definition for entities of an entity type.
Namespace
Drupal\jsonapi_schemaCode
private function createDataDefinition($field_schema) {
if (!isset($field_schema['type'])) {
return DataDefinition::createFromDataType('undefined');
}
$data_type = $field_schema['type'];
// Add additional information to the schema with the data definition.
$field_schema += $this->typedConfigManager
->getDefinition($data_type, FALSE);
$definition_class = $field_schema['definition_class'];
if (is_subclass_of($definition_class, MapDataDefinition::class)) {
$definition = call_user_func([
$definition_class,
'createFromDataType',
], $data_type)
->setTypedDataManager($this->typedDataManager);
assert($definition instanceof MapDataDefinition);
foreach ($field_schema['mapping'] as $name => $item_definition) {
$item_definition = $this
->createDataDefinition($item_definition);
$definition
->setPropertyDefinition($name, $item_definition);
}
return $definition;
}
$is_sequence = FALSE;
if (is_subclass_of($definition_class, ListDataDefinitionInterface::class)) {
$is_sequence = TRUE;
$data_type = $field_schema['sequence']['type'];
}
if ($this->typedDataManager
->hasDefinition($data_type)) {
return $is_sequence ? $this->typedDataManager
->createListDataDefinition($data_type) : $this->typedDataManager
->createDataDefinition($data_type);
}
// We tried our best. There is some information that we cannot obtain from a
//static perspective.
$data_definition = DataDefinition::createFromDataType('undefined')
->setTypedDataManager($this->typedDataManager);
if ($is_sequence) {
// Construct the sequence of 'undefined' manually.
$data_definition = ListDataDefinition::createFromDataType('sequence')
->setTypedDataManager($this->typedDataManager)
->setItemDefinition($data_definition);
}
return $data_definition;
}