function ComponentNodeVisitor::getComponent

Same name in this branch
  1. 10 core/modules/sdc/src/Twig/ComponentNodeVisitor.php \Drupal\sdc\Twig\ComponentNodeVisitor::getComponent()
Same name in other branches
  1. 11.x core/modules/sdc/src/Twig/ComponentNodeVisitor.php \Drupal\sdc\Twig\ComponentNodeVisitor::getComponent()
  2. 11.x core/lib/Drupal/Core/Template/ComponentNodeVisitor.php \Drupal\Core\Template\ComponentNodeVisitor::getComponent()

Finds the SDC for the current module node.

Parameters

\Twig\Node\Node $node: The node.

Return value

\Drupal\Core\Plugin\Component|null The component, if any.

1 call to ComponentNodeVisitor::getComponent()
ComponentNodeVisitor::leaveNode in core/lib/Drupal/Core/Template/ComponentNodeVisitor.php

File

core/lib/Drupal/Core/Template/ComponentNodeVisitor.php, line 108

Class

ComponentNodeVisitor
Provides a ComponentNodeVisitor to change the generated parse-tree.

Namespace

Drupal\Core\Template

Code

protected function getComponent(Node $node) : ?Component {
    $component_id = $node->getTemplateName();
    if (!preg_match('/^[a-z]([a-zA-Z0-9_-]*[a-zA-Z0-9])*:[a-z]([a-zA-Z0-9_-]*[a-zA-Z0-9])*$/', $component_id)) {
        return NULL;
    }
    try {
        return $this->pluginManager
            ->find($component_id);
    } catch (ComponentNotFoundException $e) {
        return NULL;
    }
}

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