Skip to content

Commit a4b1197

Browse files
feat(views): Handle vendor views
1 parent 1da357a commit a4b1197

File tree

2 files changed

+43
-5
lines changed

2 files changed

+43
-5
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,27 @@ return view('welcome');
365365
2. If the view is not found in active theme then search into parents themes recursively
366366
3. If the view is still not found then search laravel default view folder `resources/views`
367367

368+
### Package views
369+
**Themes Manager** allows you to override package views (published in `resources/views/vendor` by Laravel).
370+
You have to place your theme views into the `resources/views/vendor/namespace` directory (where namespace is the package's views namespace) of your theme.
371+
372+
For example, if you want to override `authentication-card.blade.php` from `Jestream` package we do:
373+
```sh
374+
themes
375+
├── vendorName
376+
│ ├── themeName
377+
│ │ ├── public
378+
│ │ └── resources
379+
│ │ │ ├── views
380+
│ │ │ │ ├── layouts
381+
│ │ │ │ ├── vendor
382+
│ │ │ │ │ ├── jetstream
383+
│ │ │ │ │ │ ├── components
384+
│ │ │ │ │ │ │ ├── authentication-card.blade.php
385+
```
386+
387+
This way your views will be used first before the one published into the standard `resources/views/vendor` directory.
388+
368389
## Related projects
369390
- [Laravel Theme Installer](https://github.com/hexadog/laravel-theme-installer): Composer plugin to install `laravel-theme` packages outside vendor directory .
370391

src/ThemesManager.php

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Illuminate\Support\Facades\View;
99
use Illuminate\Filesystem\Filesystem;
1010
use Illuminate\Contracts\View\Factory;
11+
use Illuminate\Support\Facades\Config;
1112
use Hexadog\ThemesManager\Traits\ComposerTrait;
1213
use Illuminate\Contracts\Translation\Translator;
1314
use Hexadog\ThemesManager\Exceptions\ThemeNotFoundException;
@@ -186,11 +187,27 @@ public function enable(string $name, bool $withEvent = true): ThemesManager
186187
View::addNamespace('theme', "{$path}");
187188
}, $paths);
188189

189-
// TODO: set list of override hints into composer.json
190-
// Add theme views path to UI-Kit package
191-
$existingHints = app('view')->getFinder()->getHints();
192-
if (!empty($existingHints['package.ui-kit'])) {
193-
View::replaceNamespace('package.ui-kit', array_merge($paths, $existingHints['package.ui-kit']));
190+
// Register all vendor views
191+
$vendorViews = $theme->getPath('resources/views/vendor');
192+
if (File::exists($vendorViews)) {
193+
$directories = scandir($vendorViews);
194+
foreach ($directories as $namespace) {
195+
if ($namespace != '.' && $namespace != '..') {
196+
$path = "{$vendorViews}{$namespace}";
197+
198+
if (!empty(Config::get('view.paths')) &&
199+
is_array(Config::get('view.paths'))
200+
) {
201+
foreach (Config::get('view.paths') as $viewPath) {
202+
if (is_dir($appPath = $viewPath . '/vendor/' . $namespace)) {
203+
View::prependNamespace($namespace, $appPath);
204+
}
205+
}
206+
}
207+
208+
View::prependNamespace($namespace, $path);
209+
}
210+
}
194211
}
195212

196213
// Add Theme language files

0 commit comments

Comments
 (0)