diff --git a/core/core.services.yml b/core/core.services.yml index d35675c..1c45cb7 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -1069,7 +1069,7 @@ services: class: Drupal\Core\Extension\InfoParser twig: class: Drupal\Core\Template\TwigEnvironment - arguments: ['@app.root', '@twig.loader', '@module_handler', '@theme_handler', '%twig.config%'] + arguments: ['@app.root', '@twig.loader', '%twig.config%'] tags: - { name: service_collector, tag: 'twig.extension', call: addExtension } twig.extension: @@ -1088,12 +1088,12 @@ services: twig.loader.chain: class: Twig_Loader_Chain twig.loader.filesystem: - class: Twig_Loader_Filesystem - arguments: ['@app.root'] + class: Drupal\Core\Template\Loader\Filesystem + arguments: ['@app.root', '@module_handler', '@theme_handler'] tags: - { name: twig.loader, priority: 100 } twig.loader.theme_registry: - class: Drupal\Core\Template\TwigThemeRegistryLoader + class: Drupal\Core\Template\Loader\ThemeRegistry arguments: ['@theme.registry'] tags: - { name: twig.loader, priority: 0 } diff --git a/core/lib/Drupal/Core/Template/Loader/Filesystem.php b/core/lib/Drupal/Core/Template/Loader/Filesystem.php new file mode 100644 index 0000000..2316e06 --- /dev/null +++ b/core/lib/Drupal/Core/Template/Loader/Filesystem.php @@ -0,0 +1,52 @@ +getModuleList() as $name => $extension) { + $namespaces[$name] = $extension->getPath(); + } + foreach ($theme_handler->listInfo() as $name => $extension) { + $namespaces[$name] = $extension->getPath(); + } + + foreach ($namespaces as $name => $path) { + $templatesDirectory = $path . '/templates'; + if (file_exists($templatesDirectory)) { + $this->addPath($templatesDirectory, $name); + } + } + } + +} diff --git a/core/lib/Drupal/Core/Template/TwigThemeRegistryLoader.php b/core/lib/Drupal/Core/Template/Loader/ThemeRegistry.php similarity index 88% rename from core/lib/Drupal/Core/Template/TwigThemeRegistryLoader.php rename to core/lib/Drupal/Core/Template/Loader/ThemeRegistry.php index 86c0c9a..346964f 100644 --- a/core/lib/Drupal/Core/Template/TwigThemeRegistryLoader.php +++ b/core/lib/Drupal/Core/Template/Loader/ThemeRegistry.php @@ -2,10 +2,10 @@ /** * @file - * Contains \Drupal\Core\Template\TwigThemeRegistryLoader. + * Contains \Drupal\Core\Template\Loader\ThemeRegistry. */ -namespace Drupal\Core\Template; +namespace Drupal\Core\Template\Loader; use Drupal\Core\Theme\Registry; @@ -14,7 +14,7 @@ * * Allows for template inheritance based on the currently active template. */ -class TwigThemeRegistryLoader extends \Twig_Loader_Filesystem { +class ThemeRegistry extends \Twig_Loader_Filesystem { /** * The theme registry used to determine which template to use. @@ -24,7 +24,7 @@ class TwigThemeRegistryLoader extends \Twig_Loader_Filesystem { protected $themeRegistry; /** - * Constructs a new TwigThemeRegistryLoader object. + * Constructs a new ThemeRegistry loader object. * * @param \Drupal\Core\Theme\Registry $theme_registry * The theme registry. diff --git a/core/lib/Drupal/Core/Template/TwigEnvironment.php b/core/lib/Drupal/Core/Template/TwigEnvironment.php index a07f459..e09d9f6 100644 --- a/core/lib/Drupal/Core/Template/TwigEnvironment.php +++ b/core/lib/Drupal/Core/Template/TwigEnvironment.php @@ -8,8 +8,6 @@ namespace Drupal\Core\Template; use Drupal\Core\PhpStorage\PhpStorageFactory; -use Drupal\Core\Extension\ModuleHandlerInterface; -use Drupal\Core\Extension\ThemeHandlerInterface; /** * A class that defines a Twig environment for Drupal. @@ -35,9 +33,13 @@ class TwigEnvironment extends \Twig_Environment { * internally. * * @param string $root - * The app root; + * The app root. + * @param \Twig_LoaderInterface $loader + * The Twig loader or loader chain. + * @param array $options + * The options for the Twig environment. */ - public function __construct($root, \Twig_LoaderInterface $loader = NULL, ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler, $options = array()) { + public function __construct($root, \Twig_LoaderInterface $loader = NULL, $options = array()) { // @todo Pass as arguments from the DIC. $this->cache_object = \Drupal::cache(); @@ -45,24 +47,6 @@ public function __construct($root, \Twig_LoaderInterface $loader = NULL, ModuleH // template because functions like twig_drupal_escape_filter are called. require_once $root . '/core/themes/engines/twig/twig.engine'; - // Set twig path namespace for themes and modules. - $namespaces = array(); - 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) { - $templatesDirectory = $path . '/templates'; - if (file_exists($templatesDirectory)) { - // @todo Inject this? Might be weird injecting two TwigLoaderInterface? - // Or solve this another way. - \Drupal::service('twig.loader.filesystem')->addPath($templatesDirectory, $name); - } - } - $this->templateClasses = array(); $options += array(