From 6bb69ed47d9a7b057e34de13935e08b6233e3fec Mon Sep 17 00:00:00 2001 From: Lennart Hammer Date: Tue, 21 Jul 2026 14:31:55 +0200 Subject: [PATCH] feat: Update FileSystemLoader to prevent issue with wrong them on init --- .../Loader/UEberToolFilesystemLoader.php | 47 +++++-------------- 1 file changed, 13 insertions(+), 34 deletions(-) diff --git a/packages/uebertool-companion/modules/uebertool_twig_loader/src/Template/Loader/UEberToolFilesystemLoader.php b/packages/uebertool-companion/modules/uebertool_twig_loader/src/Template/Loader/UEberToolFilesystemLoader.php index c416e41..64a4603 100644 --- a/packages/uebertool-companion/modules/uebertool_twig_loader/src/Template/Loader/UEberToolFilesystemLoader.php +++ b/packages/uebertool-companion/modules/uebertool_twig_loader/src/Template/Loader/UEberToolFilesystemLoader.php @@ -27,27 +27,6 @@ class UEberToolFilesystemLoader extends FilesystemLoader { */ protected $libraryDiscovery; - /** - * The active theme. - * - * @var \Drupal\Core\Theme\ActiveTheme - */ - protected $activeTheme; - - /** - * The active theme name. - * - * @var string - */ - protected $activeThemeName; - - /** - * The active theme name with _dist suffix. - * - * @var string - */ - protected $distThemeName; - /** * Constructs a new ComponentsLoader object. */ @@ -58,26 +37,26 @@ public function __construct( parent::__construct([], null); $this->themeManager = $themeManager; $this->libraryDiscovery = $library_discovery; - $this->activeTheme = $this->themeManager->getActiveTheme(); - $this->activeThemeName = $this->activeTheme->getName(); - $this->distThemeName = "{$this->activeThemeName}_dist"; - $this->addPath('.', '__main__'); - file_exists($this->activeTheme->getPath() . '/templates') && $this->addPath($this->activeTheme->getPath() . '/templates', $this->activeThemeName); - foreach ($this->activeTheme->getBaseThemeExtensions() as $baseTheme) { - $path = $baseTheme->getPath() . '/templates'; - file_exists($path) && $this->addPath($path, $baseTheme->getName()); - } } public function getSourceContext(string $name): Source { if (\Drupal::service('router.admin_context')->isAdminRoute()) { throw new LoaderError('Skipping admin route'); } + $activeTheme = $this->themeManager->getActiveTheme(); + $activeThemeName = $activeTheme->getName(); + $distThemeName = "{$activeThemeName}_dist"; + + file_exists($activeTheme->getPath() . '/templates') && $this->addPath($activeTheme->getPath() . '/templates', $activeThemeName); + foreach ($activeTheme->getBaseThemeExtensions() as $baseTheme) { + $path = $baseTheme->getPath() . '/templates'; + file_exists($path) && $this->addPath($path, $baseTheme->getName()); + } $prefix = ''; - if (array_key_exists($this->distThemeName, $this->activeTheme->getBaseThemeExtensions())) { + if (array_key_exists($distThemeName, $activeTheme->getBaseThemeExtensions())) { if (str_starts_with($name, '@')) { $libraryName = preg_replace('/@((\w|-)+\/)+|((\.html)?\.twig)/', '', $name); } @@ -86,12 +65,12 @@ public function getSourceContext(string $name): Source { } $extension = FALSE; - $libraryExists = $this->libraryDiscovery->getLibraryByName($this->distThemeName, $libraryName); + $libraryExists = $this->libraryDiscovery->getLibraryByName($distThemeName, $libraryName); if ($libraryExists) { - $extension = $this->distThemeName; + $extension = $distThemeName; } else { - foreach ($this->activeTheme->getBaseThemeExtensions() as $baseTheme) { + foreach ($activeTheme->getBaseThemeExtensions() as $baseTheme) { if ($this->libraryDiscovery->getLibraryByName($baseTheme->getName(), $libraryName)) { $extension = $baseTheme->getName(); break;