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

Breadcrumb

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

function ComponentLoader::getSourceContext

Overrides LoaderInterface::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) {
        return new Source('', $name, '');
    }
    $original_code = file_get_contents($path);
    return new Source($original_code, $name, $path);
}

API Navigation

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