Closed alibaba258 closed 3 years ago
Try to fix the problem by adding $this->themes = collect();
to the ThemesManager.php on __construct() Method.
Method now looks like this.
public function __construct(Factory $view, Translator $lang)
{
$this->view = $view;
$this->lang = $lang;
$this->themes = collect();
if (Config::get('themes-manager.cache.enabled', false)) {
$this->themes = $this->getCache();
} else {
$this->themes = $this->findThemes();
}
}
Error Message is gone, but the theme extends now the wrong parent theme.
$ php artisan theme:list
+-----------+--------+---------+-------------+-----------+---------+--------+
| Name | Vendor | Version | Description | Extends | Default | Active |
+-----------+--------+---------+-------------+-----------+---------+--------+
| default | hls | 1.0.0 | | | X | Yes |
| sauerland | hls | 1.0.0 | | sauerland | | Yes |
+-----------+--------+---------+-------------+-----------+---------+--------+
Hi,
weird because themes
variable is normally set up by following code:
if (Config::get('themes-manager.cache.enabled', false)) {
$this->themes = $this->getCache();
} else {
$this->themes = $this->findThemes();
}
Have you enabled the cache ? (what's the value returned when you call dd(Config::get('themes-manager.cache.enabled', false))
?
I can't reproduce your issue on my side.
Edit:
I found the bug...it's during the initialization of themes list : $this->findThemes();
. It tries to find the parent theme while themes collection is not yet populated.
I'm working on a fix for it.
Hi,
Cache is disable. Output of dd(Config::get('themes-manager.cache.enabled', false))
is only false
Maybe im understood something wrong but in your findThemes() method you call the following function
if ($this->has($extendedThemeName))
The has() method effectively calls the findByName Method. Here you reference $this->themes which are not initialized
EDIT:
I found the bug...it's during the initialization of themes list : $this->findThemes();. It tries to find the parent theme while themes collection is not yet populated.
Yeah thats what i mean. Thanks for help.
Hi,
after your fix i am able to create an child theme. But the plugin works not as i expected. This are my themes:
+-----------+--------+---------+-------------+---------+---------+--------+
| Name | Vendor | Version | Description | Extends | Default | Active |
+-----------+--------+---------+-------------+---------+---------+--------+
| core | hls | 1.0.0 | | | X | Yes |
| sauerland | hls | 1.0.0 | | core | | Yes |
+-----------+--------+---------+-------------+---------+---------+--------+
I don´t set a theme at runtime, so in my opinion the fallback theme should be used which is assigned to core. But if i render a view i get the following message View [categories.show] not found.
. These view exists in the core theme but i get that error. If i create the views file in the standard laravel views folder everthing works but that gives me the idea that the fallback theme is not working.
Second problem: I set a theme at runtime (Middleware, Constructor...tried both), the plugin loads always the first theme in the table. But not the theme that i selected.
I'll have a look. can you please tell me were you defined your middleware and share its code please ?
In addition: can you confirm you set the fallback_theme
in the config/themes-manager.php
file and run php artisan config:cache
again to update your cache ?
I'll have a look. can you please tell me were you defined your middleware and share its code please ?
In my Kernel.php
protected $middleware = [
// \App\Http\Middleware\TrustHosts::class,
\App\Http\Middleware\TrustProxies::class,
\Fruitcake\Cors\HandleCors::class,
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
\App\Http\Middleware\TrimStrings::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
\App\Http\Middleware\DomainCheckMiddleware::class,
];
DomainCheckMiddleware.php ist attached below. Tried Theme Name with and without vendor. Also tried to change the Theme via my Controller
public function __construct()
{
ThemesManager::set('hls/sauerland');
}
In addition: can you confirm you set the
fallback_theme
in theconfig/themes-manager.php
file and runphp artisan config:clear
again to update your cache ?
Yes can confirm that. But I have used php artisan config:clear to delete and disable the cache.
'fallback_theme' => 'core',
php artisan config:clear
dd(Config::get('themes-manager.fallback_theme'));
says 'core'
I can't reproduce the issue. Root theme and Child are working well on my side. Even the fallback theme.
Can you please try to set a dd
into the handle
method of the Hexadog\ThemesManager\Http\Middleware\ThemeLoader
middleware to check if you pass into the callback theme activation ?
public function handle($request, Closure $next, $theme = null)
{
// Do not load theme if API request
if ($request->expectsJson()) {
return $next($request);
}
if (!empty($theme)) {
ThemesManager::set($theme);
} else {
if ($theme = config('themes-manager.fallback_theme')) {
dd($theme);
ThemesManager::set($theme);
}
}
return $next($request);
}
The dd command is not executed. I get my default view. I have uploaded my Test Project. Here you can find the Repository: https://github.com/alibaba258/theme-test
Just clone and execute php artisan serve
I am expecting to see "Sauerland" but i still get "Core" from the Core Theme
Thanks for the repo.
I get your code working and commit a fix. Now on your app I can see the sauerland
theme
and the fallback core
theme when I comment line 40 in your middleware
// $theme = 'hls/sauerland';
return parent::handle($request, $next, $theme);
Please let me know if its ok on your side too.
You`re the man!! Works great. Thank you very much for your help :-)
I'm glad to hear it's working :-) Don't hesitate if you need any help
Hey all,
i am not able to create a child Theme. Multiple Themes works great. But if try to create a child Theme, i get the following errors: I'm using make:theme command. Plugin Verison 1.8 Laravel 8.12