Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ComponentPluginManager.php

function 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);
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal