You are here

public function PluginManagerBase::createInstance in Service Container 7.2

Same name in this branch
  1. 7.2 src/Plugin/PluginManagerBase.php \Drupal\service_container\Plugin\PluginManagerBase::createInstance()
  2. 7.2 lib/Drupal/Component/Plugin/PluginManagerBase.php \Drupal\Component\Plugin\PluginManagerBase::createInstance()
Same name and namespace in other branches
  1. 7 src/Plugin/PluginManagerBase.php \Drupal\service_container\Plugin\PluginManagerBase::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 FactoryInterface::createInstance

1 call to PluginManagerBase::createInstance()
PluginManagerBase::getInstance in src/Plugin/PluginManagerBase.php
Gets a preconfigured instance of a plugin.

File

src/Plugin/PluginManagerBase.php, line 57
Contains \Drupal\service_container\Plugin\PluginManagerBase

Class

PluginManagerBase
Base class for plugin managers.

Namespace

Drupal\service_container\Plugin

Code

public function createInstance($plugin_id, array $configuration = array()) {

  // If this PluginManager has fallback capabilities catch
  // PluginNotFoundExceptions.
  if ($this instanceof FallbackPluginManagerInterface) {
    try {
      return $this->factory
        ->createInstance($plugin_id, $configuration);
    } catch (PluginNotFoundException $e) {
      $fallback_id = $this
        ->getFallbackPluginId($plugin_id, $configuration);
      return $this->factory
        ->createInstance($fallback_id, $configuration);
    }
  }
  else {
    return $this->factory
      ->createInstance($plugin_id, $configuration);
  }
}