Implements \Drupal\Component\Plugin\Factory\FactoryInterface::createInstance().
string $plugin_id: The id of a plugin, i.e. the data type.
array $configuration: The plugin configuration, i.e. the data definition.
string $name: (optional) If a property or list item is to be created, the name of the property or the delta of the list item.
mixed $parent: (optional) If a property or list item is to be created, the parent typed data object implementing either the ListInterface or the ComplexDataInterface.
\Drupal\Core\TypedData\TypedDataInterface The instantiated typed data object.
Overrides DefaultFactory::createInstance
public function createInstance($plugin_id, array $configuration, $name = NULL, $parent = NULL) {
$type_definition = $this->discovery
->getDefinition($plugin_id);
if (!isset($type_definition)) {
throw new InvalidArgumentException(format_string('Invalid data type %plugin_id has been given.', array(
'%plugin_id' => $plugin_id,
)));
}
// Allow per-data definition overrides of the used classes, i.e. take over
// classes specified in the data definition.
$key = empty($configuration['list']) ? 'class' : 'list class';
if (isset($configuration[$key])) {
$class = $configuration[$key];
}
elseif (isset($type_definition[$key])) {
$class = $type_definition[$key];
}
if (!isset($class)) {
throw new PluginException(sprintf('The plugin (%s) did not specify an instance class.', $plugin_id));
}
return new $class($configuration, $name, $parent);
}