function ComponentLoader::getSourceContext

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/Template/Loader/ComponentLoader.php \Drupal\Core\Template\Loader\ComponentLoader::getSourceContext()

File

core/lib/Drupal/Core/Template/Loader/ComponentLoader.php, line 85

Class

ComponentLoader
Lets you load templates using the component ID.

Namespace

Drupal\Core\Template\Loader

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.