function ComponentPluginManager::find

Same name in this branch
  1. 11.x core/modules/sdc/src/ComponentPluginManager.php \Drupal\sdc\ComponentPluginManager::find()
Same name in other branches
  1. 10 core/modules/sdc/src/ComponentPluginManager.php \Drupal\sdc\ComponentPluginManager::find()
  2. 10 core/lib/Drupal/Core/Theme/ComponentPluginManager.php \Drupal\Core\Theme\ComponentPluginManager::find()

Gets a component for rendering.

Parameters

string $component_id: The component ID.

Return value

\Drupal\Core\Plugin\Component The component.

Throws

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

File

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

Class

ComponentPluginManager
Defines a plugin manager to deal with components.

Namespace

Drupal\Core\Theme

Code

public function find(string $component_id) : Component {
    $definitions = $this->getDefinitions();
    if (empty($definitions)) {
        throw new ComponentNotFoundException('Unable to find any component definition.');
    }
    $negotiated_plugin_id = $this->componentNegotiator
        ->negotiate($component_id, $definitions);
    return $this->createInstance($negotiated_plugin_id ?? $component_id);
}

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