public TypedDataManager::createInstance($data_type, array $configuration = array())
Creates a pre-configured instance of a plugin.
string $plugin_id: The ID of the plugin being instantiated.
array $configuration: An array of configuration relevant to the plugin instance.
object A fully configured plugin instance.
\Drupal\Component\Plugin\Exception\PluginException If the instance cannot be created, such as if the ID is invalid.
Overrides PluginManagerBase::createInstance
public function createInstance($data_type, array $configuration = array()) { $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; }
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!TypedData!TypedDataManager.php/function/TypedDataManager::createInstance/8.1.x