public function TypedDataManager::createDataDefinition in Drupal 10
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/TypedData/TypedDataManager.php \Drupal\Core\TypedData\TypedDataManager::createDataDefinition()
- 9 core/lib/Drupal/Core/TypedData/TypedDataManager.php \Drupal\Core\TypedData\TypedDataManager::createDataDefinition()
Creates a new data definition object.
While data definitions objects may be created directly if the definition class used by a data type is known, this method allows the creation of data definitions for any given data type.
For example, if a definition for a map is to be created, the following code could be used instead of calling this method with the argument 'map':
$map_definition = \Drupal\Core\TypedData\MapDataDefinition::create();
Parameters
string $data_type: The data type plugin ID, for which a data definition object should be created.
Return value
\Drupal\Core\TypedData\DataDefinitionInterface A data definition object for the given data type. The class of this object is provided by the definition_class in the plugin annotation.
Overrides TypedDataManagerInterface::createDataDefinition
See also
\Drupal\Core\TypedData\TypedDataManager::createListDataDefinition()
1 call to TypedDataManager::createDataDefinition()
- TypedConfigManager::buildDataDefinition in core/
lib/ Drupal/ Core/ Config/ TypedConfigManager.php - Creates a new data definition object from a type definition array and actual configuration data. Since type definitions may contain variables to be replaced, we need the configuration value to create it.
File
- core/
lib/ Drupal/ Core/ TypedData/ TypedDataManager.php, line 114
Class
- TypedDataManager
- Manages data type plugins.
Namespace
Drupal\Core\TypedDataCode
public function createDataDefinition($data_type) {
$type_definition = $this
->getDefinition($data_type);
if (!isset($type_definition)) {
throw new \InvalidArgumentException("Invalid data type '{$data_type}' has been given");
}
$class = $type_definition['definition_class'];
$data_definition = $class::createFromDataType($data_type);
if (method_exists($data_definition, 'setTypedDataManager')) {
$data_definition
->setTypedDataManager($this);
}
return $data_definition;
}