Skip to content

Commit

Permalink
feat(themes): Auto-set mail theme path
Browse files Browse the repository at this point in the history
Previously, the path to mail themes had to be set in the
`config/mail.php` file. This now automatically sets the path based on
current active theme.
  • Loading branch information
zooley committed Mar 27, 2024
1 parent 6bb9797 commit 6ccd23b
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions app/Modules/Themes/Providers/ThemesServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ThemesServiceProvider extends ServiceProvider
*
* @return void
*/
public function boot()
public function boot(): void
{
$this->registerTranslations();
$this->registerConfig();
Expand Down Expand Up @@ -71,26 +71,28 @@ public function boot()

if ($path = theme_path('views'))
{
$paths = array_merge([$path], config('view.paths'));
// Add module view overrides
$paths = array_merge([$path], config('view.paths', []));
config()->set('view.paths', $paths);
}

/*$paths = collect($paths);

View::replaceNamespace('errors', $paths->map(function ($path) {
return "{$path}/errors";
})->push(base_path('vendor/laravel/framework/src/Illuminate/Foundation/Exceptions') . '/views')->all());*/
// Add mail view overrides, if present
$path .= '/mail';
if (is_dir($path))
{
$paths = array_merge([$path], config('mail.markdown.paths', []));
config()->set('mail.markdown.paths', $paths);
}
}
}

/**
* Publish the assets
*/
public function publish($sourcePath, $destinationPath)
public function publish(string $sourcePath, string $destinationPath): void
{
if (!$this->app['files']->isDirectory($sourcePath))
{
$message = "Source path does not exist : {$sourcePath}";
throw new \InvalidArgumentException($message);
throw new \InvalidArgumentException("Source path does not exist : {$sourcePath}");
}

if (!$this->app['files']->isDirectory($destinationPath))
Expand Down Expand Up @@ -120,7 +122,7 @@ public function publish($sourcePath, $destinationPath)
*
* @return void
*/
public function register()
public function register(): void
{
$this->app->singleton('themes', function ($app)
{
Expand All @@ -135,7 +137,7 @@ public function register()
*
* @return void
*/
protected function registerConsoleCommands()
protected function registerConsoleCommands(): void
{
$this->commands([
InstallCommand::class,
Expand All @@ -151,7 +153,7 @@ protected function registerConsoleCommands()
*
* @return void
*/
protected function registerConfig()
protected function registerConfig(): void
{
$this->publishes([
__DIR__ . '/../Config/config.php' => config_path('module/' . $this->name . '.php'),
Expand All @@ -167,7 +169,7 @@ protected function registerConfig()
*
* @return void
*/
protected function registerAssets()
protected function registerAssets(): void
{
$this->publishes([
__DIR__ . '/../Resources/assets' => public_path() . '/modules/' . strtolower($this->name) . '/assets',
Expand All @@ -179,7 +181,7 @@ protected function registerAssets()
*
* @return void
*/
public function registerViews()
public function registerViews(): void
{
$viewPath = resource_path('views/modules/' . $this->name);

Expand All @@ -200,7 +202,7 @@ public function registerViews()
*
* @return void
*/
public function registerTranslations()
public function registerTranslations(): void
{
$langPath = resource_path('lang/modules/' . $this->name);

Expand All @@ -215,7 +217,7 @@ public function registerTranslations()
/**
* Get the services provided by the provider.
*
* @return array
* @return array<int,string>
*/
public function provides()
{
Expand Down

0 comments on commit 6ccd23b

Please sign in to comment.