function FilesystemLoader::findTemplate
Same name in other branches
- 9 core/lib/Drupal/Core/Template/Loader/FilesystemLoader.php \Drupal\Core\Template\Loader\FilesystemLoader::findTemplate()
- 10 core/lib/Drupal/Core/Template/Loader/FilesystemLoader.php \Drupal\Core\Template\Loader\FilesystemLoader::findTemplate()
File
-
core/
lib/ Drupal/ Core/ Template/ Loader/ FilesystemLoader.php, line 81
Class
- FilesystemLoader
- Loads templates from the filesystem.
Namespace
Drupal\Core\Template\LoaderCode
protected function findTemplate($name, $throw = TRUE) {
$extension = pathinfo($name, PATHINFO_EXTENSION);
if (!in_array($extension, $this->allowedFileExtensions, TRUE)) {
if (!$throw) {
return NULL;
}
// Customize the list of extensions if no file extension is allowed.
$extensions = $this->allowedFileExtensions;
$no_extension = array_search('', $extensions, TRUE);
if (is_int($no_extension)) {
unset($extensions[$no_extension]);
$extensions[] = 'or no file extension';
}
if (empty($extension)) {
$extension = 'no file extension';
}
throw new LoaderError(sprintf("Template %s has an invalid file extension (%s). Only templates ending in one of %s are allowed. Set the twig.config.allowed_file_extensions container parameter to customize the allowed file extensions", $name, $extension, implode(', ', $extensions)));
}
// Previously it was possible to access files in the parent directory of a
// namespace. This was removed in Twig 2.15.3. In order to support backwards
// compatibility, we are adding path directory as a namespace, and therefore
// we can remove the directory traversal from the name.
// @todo deprecate this functionality for removal in Drupal 11.
if (preg_match('/(^\\@[^\\/]+\\/)\\.\\.\\/(.*)/', $name, $matches)) {
$name = $matches[1] . $matches[2];
}
return parent::findTemplate($name, $throw);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.