From b56a9a31ed342aa6ea0bd8828df812dd1fda7fa3 Mon Sep 17 00:00:00 2001 From: Tony Lea Date: Tue, 30 Jul 2024 09:37:50 -0400 Subject: [PATCH 1/2] Adding themes default location to the resources/themes --- README.md | 6 ++++-- config/themes.php | 2 +- resources/views/options.blade.php | 2 +- src/Http/Controllers/ThemesController.php | 2 +- src/ThemesServiceProvider.php | 6 ++++-- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 0c42f7f..4eb817a 100644 --- a/README.md +++ b/README.md @@ -42,14 +42,16 @@ You will want to publish the themes config, and you will now see a new config lo return [ - 'themes_folder' => resource_path('views/themes'), + 'folder' => resource_path('themes'), 'publish_assets' => true, 'create_tables' => true ]; ``` -Now, you can choose an alternate location for your themes folder. By default this will be put into the `resources/views` folder; however, you can change that to any location you would like. +Now, you can choose an alternate location for your themes folder. By default this will be put into the `resources` folder; however, you can change that to any location you would like. + +> Warning, If you add the themes folder into the `resources/views` folder and you run `php artisan optimize` you may get an error that it cannot find certain components. This is because it will search all the `.blade.php` files inside the views folder. So, this may not be the best place to put your themes. Instead this package will register only the views of the active theme. Additionally, you can set **publish_assets** to *true* or *false*, if it is set to *true* anytime the themes directory is scanned it will publish the `assets` folder in your theme to the public folder inside a new `themes` folder. Set this to *false* and this will no longer happen. diff --git a/config/themes.php b/config/themes.php index 282c00a..3f5d041 100644 --- a/config/themes.php +++ b/config/themes.php @@ -2,7 +2,7 @@ return [ - 'themes_folder' => resource_path('views/themes'), + 'folder' => resource_path('views/themes'), 'publish_assets' => true, 'create_tables' => true diff --git a/resources/views/options.blade.php b/resources/views/options.blade.php index c24188d..dc2649a 100644 --- a/resources/views/options.blade.php +++ b/resources/views/options.blade.php @@ -58,7 +58,7 @@
- @if(file_exists(config('themes.themes_folder', resource_path('views/themes')) . '/' . $theme->folder . '/options.blade.php')) + @if(file_exists(config('themes.folder', resource_path('views/themes')) . '/' . $theme->folder . '/options.blade.php')) folder); } ?>
diff --git a/src/Http/Controllers/ThemesController.php b/src/Http/Controllers/ThemesController.php index d9d3542..c0199bc 100644 --- a/src/Http/Controllers/ThemesController.php +++ b/src/Http/Controllers/ThemesController.php @@ -14,7 +14,7 @@ class ThemesController extends Controller private $themes_folder = ''; public function __construct(){ - $this->themes_folder = config('themes.themes_folder', resource_path('views/themes')); + $this->themes_folder = config('themes.folder', resource_path('views/themes')); } public function index(){ diff --git a/src/ThemesServiceProvider.php b/src/ThemesServiceProvider.php index 4252d85..b7ede45 100644 --- a/src/ThemesServiceProvider.php +++ b/src/ThemesServiceProvider.php @@ -32,7 +32,7 @@ class ThemesServiceProvider extends ServiceProvider */ public function register() { - if ( request()->is(config('voyager.prefix')) || request()->is(config('voyager.prefix').'/*') || app()->runningInConsole() ) { + if ( app()->runningInConsole() ) { try { DB::connection()->getPdo(); @@ -66,6 +66,8 @@ public function boot() { try{ + dd(config('themes.folder')); + $this->loadViewsFrom(__DIR__.'/../resources/views', 'themes'); $theme = ''; @@ -84,7 +86,7 @@ public function boot() view()->share('theme', $theme); - $this->themes_folder = config('themes.themes_folder', resource_path('views/themes')); + $this->themes_folder = config('themes.folder', resource_path('views/themes')); $this->loadDynamicMiddleware($this->themes_folder, $theme); $this->registerThemeComponents($theme); From 5f08d3a7fec862f57a601c4d45cae44277220659 Mon Sep 17 00:00:00 2001 From: Tony Lea Date: Tue, 30 Jul 2024 14:53:14 -0400 Subject: [PATCH 2/2] Adding updates to themes --- config/themes.php | 4 +--- resources/views/index.blade.php | 2 +- resources/views/options.blade.php | 2 +- src/Http/Controllers/ThemesController.php | 2 +- src/ThemesServiceProvider.php | 24 +++++++++++------------ 5 files changed, 16 insertions(+), 18 deletions(-) diff --git a/config/themes.php b/config/themes.php index 3f5d041..7edc6ac 100644 --- a/config/themes.php +++ b/config/themes.php @@ -1,9 +1,7 @@ resource_path('views/themes'), + 'folder' => resource_path('themes'), 'publish_assets' => true, 'create_tables' => true - ]; \ No newline at end of file diff --git a/resources/views/index.blade.php b/resources/views/index.blade.php index b818327..bbc4910 100644 --- a/resources/views/index.blade.php +++ b/resources/views/index.blade.php @@ -164,7 +164,7 @@ @if(count($themes) < 1)
Wuh oh! -

It doesn't look like you have any themes available in your theme folder located at

+

It doesn't look like you have any themes available in your theme folder located at

@endif diff --git a/resources/views/options.blade.php b/resources/views/options.blade.php index dc2649a..a672a3c 100644 --- a/resources/views/options.blade.php +++ b/resources/views/options.blade.php @@ -58,7 +58,7 @@
- @if(file_exists(config('themes.folder', resource_path('views/themes')) . '/' . $theme->folder . '/options.blade.php')) + @if(file_exists(config('themes.folder', resource_path('themes')) . '/' . $theme->folder . '/options.blade.php')) folder); } ?> diff --git a/src/Http/Controllers/ThemesController.php b/src/Http/Controllers/ThemesController.php index c0199bc..e5a551e 100644 --- a/src/Http/Controllers/ThemesController.php +++ b/src/Http/Controllers/ThemesController.php @@ -14,7 +14,7 @@ class ThemesController extends Controller private $themes_folder = ''; public function __construct(){ - $this->themes_folder = config('themes.folder', resource_path('views/themes')); + $this->themes_folder = config('themes.folder', resource_path('themes')); } public function index(){ diff --git a/src/ThemesServiceProvider.php b/src/ThemesServiceProvider.php index b7ede45..0b0f844 100644 --- a/src/ThemesServiceProvider.php +++ b/src/ThemesServiceProvider.php @@ -66,9 +66,9 @@ public function boot() { try{ - dd(config('themes.folder')); + // dd(config('themes.folder')); - $this->loadViewsFrom(__DIR__.'/../resources/views', 'themes'); + //$this->loadViewsFrom(config('themes.folder'), 'themes'); $theme = ''; @@ -86,17 +86,17 @@ public function boot() view()->share('theme', $theme); - $this->themes_folder = config('themes.folder', resource_path('views/themes')); + $folder = config('themes.folder', resource_path('themes')); - $this->loadDynamicMiddleware($this->themes_folder, $theme); + $this->loadDynamicMiddleware($folder, $theme); $this->registerThemeComponents($theme); $this->registerThemeFolioDirectory($theme); // Make sure we have an active theme if (isset($theme)) { - $this->loadViewsFrom($this->themes_folder.'/'.@$theme->folder, 'theme'); + $this->loadViewsFrom($folder.'/'.@$theme->folder, 'theme'); } - $this->loadViewsFrom($this->themes_folder, 'themes_folder'); + //$this->loadViewsFrom($folder, 'themes_folder'); } catch(\Exception $e){ return $e->getMessage(); @@ -122,13 +122,13 @@ public function addThemeRoutes($router) } private function registerThemeComponents($theme){ - Blade::anonymousComponentPath(resource_path('views/themes/' . $theme->folder . '/components/elements')); - Blade::anonymousComponentPath(resource_path('views/themes/' . $theme->folder . '/components')); + Blade::anonymousComponentPath(config('themes.folder') . '/' . $theme->folder . '/components/elements'); + Blade::anonymousComponentPath(config('themes.folder') . '/' . $theme->folder . '/components'); } private function registerThemeFolioDirectory($theme){ - if (File::exists(resource_path('views/themes/' . $theme->folder . '/pages'))) { - Folio::path(resource_path('views/themes/' . $theme->folder . '/pages'))->middleware([ + if (File::exists( config('themes.folder') . '/' . $theme->folder . '/pages')) { + Folio::path( config('themes.folder') . '/' . $theme->folder . '/pages')->middleware([ '*' => [ // ], @@ -184,11 +184,11 @@ protected function ensurePermissionExist() } } - private function loadDynamicMiddleware($themes_folder, $theme){ + private function loadDynamicMiddleware($folder, $theme){ if (empty($theme)) { return; } - $middleware_folder = $themes_folder . '/' . $theme->folder . '/middleware'; + $middleware_folder = $folder . '/' . $theme->folder . '/middleware'; if(file_exists( $middleware_folder )){ $middleware_files = scandir($middleware_folder); foreach($middleware_files as $middleware){