From cb0af2cecf1d2f148c1b8d48e8e54ea14040b13f Mon Sep 17 00:00:00 2001 From: ttimot24 Date: Tue, 3 Dec 2024 16:37:08 +0100 Subject: [PATCH] Bind theme in service provider --- app/Controllers/WebsiteController.php | 7 ++----- app/Providers/ThemeServiceProvider.php | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/app/Controllers/WebsiteController.php b/app/Controllers/WebsiteController.php index 6a58ade7c..c89107aef 100644 --- a/app/Controllers/WebsiteController.php +++ b/app/Controllers/WebsiteController.php @@ -19,12 +19,9 @@ class WebsiteController extends Controller private $theme; - public function __construct(Request $request){ - + public function __construct(Request $request, \App\Libs\Theme $theme){ $this->request = $request; - - $this->theme = new \App\Libs\Theme(\Settings::get('theme')); - + $this->theme = $theme; } /** diff --git a/app/Providers/ThemeServiceProvider.php b/app/Providers/ThemeServiceProvider.php index 02d02e29a..a86b6636e 100644 --- a/app/Providers/ThemeServiceProvider.php +++ b/app/Providers/ThemeServiceProvider.php @@ -19,10 +19,12 @@ public function boot() $theme = new Theme(\App\Model\Settings::get('theme')); - // For website - if (!\Request::is(\Config::get('horizontcms.backend_prefix') . "/*")) { - $this->loadJsonTranslationsFrom(base_path($theme->getPath() . "resources/lang")); - } + $this->app->bind(Theme::class, function ($app) use($theme) { + return $theme; + }); + + + $this->registerTranslations($theme); $this->registerThemeViews($theme); @@ -31,6 +33,12 @@ public function boot() } } + protected function registerTranslations(Theme $theme){ + if (!\Request::is(\Config::get('horizontcms.backend_prefix') . "/*")) { + $this->loadJsonTranslationsFrom(base_path($theme->getPath() . "resources/lang")); + } + } + protected function registerThemeViews(Theme $theme){ \View::addNamespace('theme', [ $theme->getPath() . "app" . DIRECTORY_SEPARATOR . "View",