function ComponentPluginManager::createInstance

Same name in this branch
  1. 11.x core/modules/sdc/src/ComponentPluginManager.php \Drupal\sdc\ComponentPluginManager::createInstance()
Same name and namespace in other branches
  1. 10 core/modules/sdc/src/ComponentPluginManager.php \Drupal\sdc\ComponentPluginManager::createInstance()

Creates an instance.

@internal

Throws

\Drupal\Core\Render\Component\Exception\ComponentNotFoundException

Overrides PluginManagerBase::createInstance

1 call to ComponentPluginManager::createInstance()
ComponentPluginManager::find in core/lib/Drupal/Core/Theme/ComponentPluginManager.php
Gets a component for rendering.

File

core/lib/Drupal/Core/Theme/ComponentPluginManager.php, line 96

Class

ComponentPluginManager
Defines a plugin manager to deal with components.

Namespace

Drupal\Core\Theme

Code

public function createInstance($plugin_id, array $configuration = []) : Component {
    $configuration['app_root'] = $this->appRoot;
    $configuration['enforce_schemas'] = $this->shouldEnforceSchemas($this->definitions[$plugin_id] ?? []);
    try {
        $instance = parent::createInstance($plugin_id, $configuration);
        if (!$instance instanceof Component) {
            throw new ComponentNotFoundException(sprintf('Unable to find component "%s" in the component repository.', $plugin_id));
        }
        return $instance;
    } catch (PluginException $e) {
        // Cast the PluginNotFound to a more specific exception.
        $message = sprintf('Unable to find component "%s" in the component repository. [%s]', $plugin_id, $e->getMessage());
        throw new ComponentNotFoundException($message, $e->getCode(), $e);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.