public function TypedDataManager::createInstance in Drupal 8
Same name and namespace in other branches
- 9 core/lib/Drupal/Core/TypedData/TypedDataManager.php \Drupal\Core\TypedData\TypedDataManager::createInstance()
- 10 core/lib/Drupal/Core/TypedData/TypedDataManager.php \Drupal\Core\TypedData\TypedDataManager::createInstance()
Creates a pre-configured instance of a plugin.
Parameters
string $plugin_id: The ID of the plugin being instantiated.
array $configuration: An array of configuration relevant to the plugin instance.
Return value
object A fully configured plugin instance.
Throws
\Drupal\Component\Plugin\Exception\PluginException If the instance cannot be created, such as if the ID is invalid.
Overrides PluginManagerBase::createInstance
1 call to TypedDataManager::createInstance()
- TypedDataManager::create in core/
lib/ Drupal/ Core/ TypedData/ TypedDataManager.php - Creates a new typed data object instance.
File
- core/
lib/ Drupal/ Core/ TypedData/ TypedDataManager.php, line 76
Class
- TypedDataManager
- Manages data type plugins.
Namespace
Drupal\Core\TypedDataCode
public function createInstance($data_type, array $configuration = []) {
$data_definition = $configuration['data_definition'];
$type_definition = $this
->getDefinition($data_type);
if (!isset($type_definition)) {
throw new \InvalidArgumentException("Invalid data type '{$data_type}' has been given");
}
// Allow per-data definition overrides of the used classes, i.e. take over
// classes specified in the type definition.
$class = $data_definition
->getClass();
if (!isset($class)) {
throw new PluginException(sprintf('The plugin (%s) did not specify an instance class.', $data_type));
}
$typed_data = $class::createInstance($data_definition, $configuration['name'], $configuration['parent']);
$typed_data
->setTypedDataManager($this);
return $typed_data;
}