diff --git a/core/lib/Drupal/Core/CoreServiceProvider.php b/core/lib/Drupal/Core/CoreServiceProvider.php index c72cafc..f87398c 100644 --- a/core/lib/Drupal/Core/CoreServiceProvider.php +++ b/core/lib/Drupal/Core/CoreServiceProvider.php @@ -82,7 +82,7 @@ public function register(ContainerBuilder $container) { * This method is public and static so that it can be reused in the installer. */ public static function registerTwig(ContainerBuilder $container) { - $container->register('twig.loader.filesystem', 'Twig_Loader_Filesystem') + $container->register('twig.loader.filesystem', 'Drupal\Core\Template\TwigThemeRegistryLoader') ->addArgument(DRUPAL_ROOT); $container->setAlias('twig.loader', 'twig.loader.filesystem'); diff --git a/core/lib/Drupal/Core/Template/TwigThemeRegistryLoader.php b/core/lib/Drupal/Core/Template/TwigThemeRegistryLoader.php new file mode 100644 index 0000000..27987ca --- /dev/null +++ b/core/lib/Drupal/Core/Template/TwigThemeRegistryLoader.php @@ -0,0 +1,76 @@ +cache[$name])) { + return $this->cache[$name]; + } + + $this->validateName($name); + + $namespace = self::MAIN_NAMESPACE; + $shortname = $name; + if (isset($name[0]) && '@' == $name[0]) { + if (false === $pos = strpos($name, '/')) { + throw new \Twig_Error_Loader(sprintf('Malformed namespaced template name "%s" (expecting "@namespace/template_name").', $name)); + } + + $namespace = substr($name, 1, $pos - 1); + $shortname = substr($name, $pos + 1); + } + + if (!isset($this->paths[$namespace])) { + throw new \Twig_Error_Loader(sprintf('There are no registered paths for namespace "%s".', $namespace)); + } + + foreach ($this->paths[$namespace] as $path) { + if (is_file($path . '/' . $shortname)) { + return $this->cache[$name] = $path . '/' . $shortname; + } + } + + // Allow for loading based on the theme registry. + $hook = str_replace('.html.twig', '', strtr($name, '-', '_')); + $theme_registry = \Drupal::service('theme.registry')->getRuntime(); + + if ($theme_registry->has($hook)) { + $info = $theme_registry->get($hook); + print_r($info); + if (isset($info['path'])) { + $path = $info['path'] . '/' . $name; + } + elseif (isset($info['template'])) { + $path = $info['template'] . '.html.twig'; + } + if (isset($path) && is_file($path)) { + return $this->cache[$name] = $path; + } + } + + throw new \Twig_Error_Loader(sprintf('Unable to find template "%s" (looked into: %s).', $name, implode(', ', $this->paths[$namespace]))); + } + +}