TypedDataManager::createInstance

public TypedDataManager::createInstance($data_type, array $configuration = array())

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

File

core/lib/Drupal/Core/TypedData/TypedDataManager.php, line 76

Class

TypedDataManager
Manages data type plugins.

Namespace

Drupal\Core\TypedData

Code

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;
}
doc_Drupal
2016-10-29 09:50:07
Comments
Leave a Comment

Please login to continue.