FIX: fix theme:set command.

This command did not set theme properly, when THEME was in .env file, but with no value (THEME= only - as default in .env.example).
This commit is contained in:
Michal Kváček
2016-04-04 20:20:33 +02:00
parent 85dcf29c41
commit f27ad7c421
3 changed files with 44 additions and 29 deletions
+20 -20
View File
@@ -13,12 +13,12 @@ use App\Handlers\Search\Presenters\AdminContent as AdminContentPresenter;
use App\Handlers\Search\Presenters\AdminFiles;
use App\Models\Template;
use App\Widgets\HtmlCode\HtmlCode;
use App\Widgets\Menu\Extensions\URL;
use App\Widgets\Menu\Menu;
use App\Widgets\OrbitSlider\OrbitSlider;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\File;
use Illuminate\Support\ServiceProvider;
use Symfony\Component\Process\Exception\InvalidArgumentException;
class AppServiceProvider extends ServiceProvider
{
@@ -39,6 +39,13 @@ class AppServiceProvider extends ServiceProvider
$this->registerTemplates();
$this->registerSettings();
$this->registerSearch();
// check if given template is valid
$theme = config('app.theme');
$themeDir = resource_path('views/visitor/' . $theme);
if (!$theme || empty($theme) || !is_dir($themeDir)) {
throw new InvalidArgumentException('No or invalid theme set! Use artisan theme:set or edit .env file manually and include THEME option, please');
}
}
/**
@@ -95,8 +102,8 @@ class AppServiceProvider extends ServiceProvider
$registrator->register(OrbitSlider::class);
// register some menu extensions
// $menuExtensions = $this->app->make('registerMenuExtension');
// $menuExtensions->register(new URL());
// $menuExtensions = $this->app->make('registerMenuExtension');
// $menuExtensions->register(new URL());
}
/**
@@ -140,35 +147,28 @@ class AppServiceProvider extends ServiceProvider
*/
private function publishViewResources()
{
$themes = File::directories(resource_path('views/visitor'));
$theme = config('app.theme');
$themeDir = resource_path('views/visitor/' . $theme);
$assets = [];
foreach ($themes as $theme) {
$themeName = basename($theme);
if (is_dir($theme . '/'.Template::ASSETS_DIRECTORY)) {
$assets[$theme . '/'.Template::ASSETS_DIRECTORY] = public_path('assets/' . $themeName);
}
if (is_dir($theme . '/'.Template::MODULES_DIRECTORY)) {
$this->publishModuleViews($theme . '/'.Template::MODULES_DIRECTORY, $themeName);
}
// publish assets if exists for current theme
if (is_dir($themeDir . '/' . Template::ASSETS_DIRECTORY)) {
$this->publishes([$themeDir . '/' . Template::ASSETS_DIRECTORY => public_path('assets/' . $theme)], 'public-assets');
}
if (!empty($assets)) {
$this->publishes($assets, 'public-assets');
if (is_dir($themeDir . '/' . Template::MODULES_DIRECTORY)) {
// $this->publishModuleViews($themeDir . '/' . Template::MODULES_DIRECTORY);
}
}
private function publishModuleViews($themeModules, $themeName)
private function publishModuleViews($themeModules)
{
$theme = config('app.theme');
$modules = File::directories($themeModules);
$moduleViews = [];
foreach ($modules as $module) {
$moduleName = strtolower(basename($module));
$moduleViews[$module] = resource_path('views/modules/' . $moduleName . '/visitor/' . $themeName);
$moduleViews[$module] = resource_path('views/modules/' . $moduleName . '/visitor/' . $theme);
}
if (!empty($moduleViews)) {