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

Breadcrumb

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

function FilesystemLoader::__construct

Same name in this branch
  1. 11.1.x vendor/twig/twig/src/Loader/FilesystemLoader.php \Twig\Loader\FilesystemLoader::__construct()

Constructs a new FilesystemLoader object.

Parameters

string|array $paths: A path or an array of paths to check for templates.

\Drupal\Core\Extension\ModuleHandlerInterface $module_handler: The module handler service.

\Drupal\Core\Extension\ThemeHandlerInterface $theme_handler: The theme handler service.

mixed[] $twig_config: Twig configuration from the service container.

Overrides FilesystemLoader::__construct

File

core/lib/Drupal/Core/Template/Loader/FilesystemLoader.php, line 38

Class

FilesystemLoader
Loads templates from the filesystem.

Namespace

Drupal\Core\Template\Loader

Code

public function __construct($paths, ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler, array $twig_config = []) {
    parent::__construct($paths);
    // Add namespaced paths for modules and themes.
    $namespaces = [];
    foreach ($module_handler->getModuleList() as $name => $extension) {
        $namespaces[$name] = $extension->getPath();
    }
    foreach ($theme_handler->listInfo() as $name => $extension) {
        $namespaces[$name] = $extension->getPath();
    }
    foreach ($namespaces as $name => $path) {
        $this->addPath($path . '/templates', $name);
        // Allow accessing the root of an extension by using the namespace without
        // using directory traversal from the `/templates` directory.
        $this->addPath($path, $name);
    }
    if (!empty($twig_config['allowed_file_extensions'])) {
        // Provide a safe fallback for sites that have not updated their
        // services.yml file or rebuilt the container, as well as for child
        // classes.
        $this->allowedFileExtensions = $twig_config['allowed_file_extensions'];
    }
}

API Navigation

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