Skip to content

Commit 9b08679

Browse files
fix(mail): issue with overriding mail template
Markdown class is a singleton so we have to use `loadComponentsFrom` to update paths to load views from
1 parent 186502c commit 9b08679

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

src/Theme.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Hexadog\ThemesManager\Traits\ComposerTrait;
1010
use Illuminate\Container\Container;
1111
use Illuminate\Filesystem\Filesystem;
12+
use Illuminate\Mail\Markdown;
1213
use Illuminate\Support\Facades\Config;
1314
use Illuminate\Support\Facades\File;
1415
use Illuminate\Support\Facades\Log;
@@ -230,7 +231,7 @@ public function disable(bool $withEvent = true): Theme
230231
/**
231232
* Enable the current theme.
232233
*/
233-
public function enable(bool $withEvent = true): Theme
234+
public function enable(bool $withEvent = true, $defaultViewPaths = null, $defaultMailViewPaths = null): Theme
234235
{
235236
// Check if current is active and currently disabled
236237
if ($this->isActive() && $this->disabled()) {
@@ -239,7 +240,7 @@ public function enable(bool $withEvent = true): Theme
239240
}
240241

241242
$this->setStatus(true);
242-
$this->registerViews();
243+
$this->registerViews($defaultViewPaths, $defaultMailViewPaths);
243244

244245
if ($withEvent) {
245246
event(new ThemeEnabled($this->getName()));
@@ -364,7 +365,7 @@ protected function createPublicAssetsStructure()
364365
/**
365366
* Register theme's views in ViewFinder.
366367
*/
367-
protected function registerViews()
368+
protected function registerViews($defaultViewPaths, $defaultMailViewPaths)
368369
{
369370
// Create symlink for public resources if not existing yet
370371
$assetsPath = $this->getPath('public');
@@ -390,8 +391,8 @@ protected function registerViews()
390391
}, $paths);
391392

392393
// Update config view.paths to work with errors views
393-
if (is_array(Config::get('view.paths'))) {
394-
Config::set('view.paths', array_merge($paths, Config::get('view.paths')));
394+
if (is_array($this->defaultViewPaths)) {
395+
Config::set('view.paths', array_merge($paths, $defaultViewPaths));
395396
} else {
396397
Config::set('view.paths', $paths);
397398
}
@@ -416,13 +417,15 @@ protected function registerViews()
416417
// Update config mail.markdown.paths to work with mail views
417418
$mailViewsPath = $this->getPath('resources/views/vendor/mail');
418419
if (File::exists($vendorViewsPath) && is_dir($mailViewsPath)) {
419-
if (is_array(Config::get('mail.markdown.paths'))) {
420+
if (is_array($defaultMailViewPaths)) {
420421
Config::set('mail.markdown.paths', array_merge([
421422
$mailViewsPath,
422-
], Config::get('mail.markdown.paths')));
423+
], $defaultMailViewPaths));
423424
} else {
424-
Config::set('mail.markdown.paths', $mailViewsPath);
425+
Config::set('mail.markdown.paths', [$mailViewsPath]);
425426
}
427+
428+
app()->make(Markdown::class)->loadComponentsFrom(Config::get('mail.markdown.paths'));
426429
}
427430
}
428431
}

src/ThemesManager.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,20 @@ class ThemesManager
4545
*/
4646
private $view;
4747

48+
/**
49+
* Laravel default view paths
50+
*
51+
* @var [type]
52+
*/
53+
protected $defaultViewPaths;
54+
55+
/**
56+
* Laravel default Mail view paths
57+
*
58+
* @var [type]
59+
*/
60+
protected $defaultMailViewPaths;
61+
4862
/**
4963
* The constructor.
5064
*
@@ -56,6 +70,11 @@ public function __construct(Factory $view, Translator $lang)
5670
$this->view = $view;
5771
$this->lang = $lang;
5872

73+
// Save default Laravel View Paths
74+
$this->defaultViewPaths = Config::get('view.paths');
75+
// Save default Laravel Mail View Paths
76+
$this->defaultMailViewPaths = Config::get('mail.markdown.paths');
77+
5978
if (Config::get('themes-manager.cache.enabled', false)) {
6079
$this->themes = $this->getCache();
6180
} else {
@@ -172,7 +191,7 @@ public function enable(string $name, bool $withEvent = true): ThemesManager
172191
throw new ThemeNotActiveException($name);
173192
}
174193

175-
$theme->enable($withEvent);
194+
$theme->enable($withEvent, $this->defaultViewPaths, $this->defaultMailViewPaths);
176195

177196
// Add Theme language files
178197
$this->lang->addNamespace('theme', $theme->getPath('lang'));

0 commit comments

Comments
 (0)