Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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);
}
Expand All @@ -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;
Expand Down