You are here

public function FormatterPluginManager::createInstance in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Field/FormatterPluginManager.php \Drupal\Core\Field\FormatterPluginManager::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 FormatterPluginManager::createInstance()
FormatterPluginManager::getInstance in core/lib/Drupal/Core/Field/FormatterPluginManager.php
Overrides PluginManagerBase::getInstance().

File

core/lib/Drupal/Core/Field/FormatterPluginManager.php, line 55

Class

FormatterPluginManager
Plugin type manager for field formatters.

Namespace

Drupal\Core\Field

Code

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

  // @todo This is copied from \Drupal\Core\Plugin\Factory\ContainerFactory.
  //   Find a way to restore sanity to
  //   \Drupal\Core\Field\FormatterBase::__construct().
  // 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['field_definition'], $configuration['settings'], $configuration['label'], $configuration['view_mode'], $configuration['third_party_settings']);
}