function TwigComponentLoader::getSourceContext

Same name and namespace in other branches
  1. 10 core/modules/sdc/src/Twig/TwigComponentLoader.php \Drupal\sdc\Twig\TwigComponentLoader::getSourceContext()

File

core/modules/sdc/src/Twig/TwigComponentLoader.php, line 87

Class

TwigComponentLoader
Lets you load templates using the component ID.

Namespace

Drupal\sdc\Twig

Code

public function getSourceContext($name) : Source {
    try {
        $component = $this->pluginManager
            ->find($name);
        $path = $component->getTemplatePath();
    } catch (ComponentNotFoundException $e) {
        return new Source('', $name, '');
    }
    $original_code = file_get_contents($path);
    return new Source($original_code, $name, $path);
}

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