You are here

public function FieldGroupFormatterPluginManager::createInstance in Field Group 8

Same name and namespace in other branches
  1. 8.3 src/FieldGroupFormatterPluginManager.php \Drupal\field_group\FieldGroupFormatterPluginManager::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 FieldGroupFormatterPluginManager::createInstance()
FieldGroupFormatterPluginManager::getInstance in src/FieldGroupFormatterPluginManager.php
Overrides PluginManagerBase::getInstance().

File

src/FieldGroupFormatterPluginManager.php, line 38

Class

FieldGroupFormatterPluginManager
Plugin type manager for all fieldgroup formatters.

Namespace

Drupal\field_group

Code

public function createInstance($plugin_id, array $configuration = array()) {
  $plugin_definition = $this
    ->getDefinition($plugin_id);
  $plugin_class = DefaultFactory::getPluginClass($plugin_id, $plugin_definition);

  // If the plugin provides a factory method, pass the container to it.
  if (is_subclass_of($plugin_class, 'Drupal\\Core\\Plugin\\ContainerFactoryPluginInterface')) {
    return $plugin_class::create(\Drupal::getContainer(), $configuration, $plugin_id, $plugin_definition);
  }
  return new $plugin_class($plugin_id, $plugin_definition, $configuration['group'], $configuration['settings'], $configuration['label']);
}