Merge branch 'template_support' into dev
This commit is contained in:
@@ -30,8 +30,6 @@ class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
// ignore running from artisan
|
||||
if (App::runningInConsole()) {
|
||||
$this->publishViewResources();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -39,13 +37,6 @@ 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');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -120,10 +111,10 @@ class AppServiceProvider extends ServiceProvider
|
||||
/**
|
||||
* @var $registrator TemplateRegistrator
|
||||
*/
|
||||
$registrator = $this->app->make('registerTemplateDir');
|
||||
$registrator->setBaseDirectory('resources/views/visitor');
|
||||
// $registrator = $this->app->make('registerTemplateDir');
|
||||
// $registrator->setBaseDirectory('resources/views/visitor');
|
||||
|
||||
$registrator->register(config('app.theme'), 'admin/templates.core');
|
||||
// $registrator->register(config('app.theme'), 'admin/templates.core');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -150,37 +141,5 @@ class AppServiceProvider extends ServiceProvider
|
||||
$registrator->register(new Files(), new AdminFiles(), SearchEngineRegistrator::ADMIN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Publish all public assets from all themes
|
||||
*/
|
||||
private function publishViewResources()
|
||||
{
|
||||
$theme = config('app.theme');
|
||||
$themeDir = resource_path('views/visitor/' . $theme);
|
||||
|
||||
// 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 (is_dir($themeDir . '/' . Template::MODULES_DIRECTORY)) {
|
||||
$this->publishModuleViews($themeDir . '/' . Template::MODULES_DIRECTORY);
|
||||
}
|
||||
}
|
||||
|
||||
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/' . $theme);
|
||||
}
|
||||
|
||||
if (!empty($moduleViews)) {
|
||||
$this->publishes($moduleViews, 'module-views');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,18 +5,13 @@ use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
||||
use Symfony\Component\Translation\Translator;
|
||||
|
||||
class LaravelLocalizationServiceProvider extends ServiceProvider
|
||||
{
|
||||
public function register()
|
||||
{
|
||||
try {
|
||||
$languages = DB::table('languages')
|
||||
->get();
|
||||
} catch (\Exception $e) {
|
||||
$languages = [];
|
||||
}
|
||||
$languages = DB::table('languages')
|
||||
->get();
|
||||
|
||||
$supportedLocales = [];
|
||||
if (empty($languages)) {
|
||||
@@ -28,11 +23,7 @@ class LaravelLocalizationServiceProvider extends ServiceProvider
|
||||
];
|
||||
|
||||
// create default language
|
||||
try {
|
||||
Language::create($supportedLocales[config('app.locale')]);
|
||||
} catch (\Exception $e) {
|
||||
// ignore, table languages probably does not exist.
|
||||
}
|
||||
Language::create($supportedLocales[config('app.locale')]);
|
||||
}
|
||||
|
||||
foreach ($languages as $language) {
|
||||
|
||||
@@ -21,7 +21,8 @@ class ModuleManager extends ServiceProvider
|
||||
}
|
||||
|
||||
// this service provider needs published config - config is merged right after this service provider
|
||||
$modules = Module::get();
|
||||
$modules = Module::where('is_template', false)
|
||||
->get();
|
||||
|
||||
// iterate over all modules and enable or disable them
|
||||
foreach ($modules as $module) {
|
||||
@@ -58,7 +59,7 @@ class ModuleManager extends ServiceProvider
|
||||
|
||||
// check if module config is writable
|
||||
if (!is_writable(dirname($path))) {
|
||||
Log::warning('Cannot write to '.$path);
|
||||
Log::warning('Cannot write to ' . $path);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Handlers\Registrators\TemplateRegistrator;
|
||||
use App\Models\Module;
|
||||
use App\Models\Template;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use InvalidArgumentException;
|
||||
|
||||
class TemplateServiceProvider extends ServiceProvider
|
||||
{
|
||||
private function getTemplate()
|
||||
{
|
||||
// select template
|
||||
$template = Module::where('is_template', true)
|
||||
->where('enabled', true)
|
||||
->first();
|
||||
|
||||
if ($template) {
|
||||
$template->settings = json_decode($template->module_settings);
|
||||
}
|
||||
|
||||
return $template;
|
||||
}
|
||||
|
||||
public function boot()
|
||||
{
|
||||
// ignore running from artisan
|
||||
if (App::runningInConsole()) {
|
||||
$this->publishViewResources();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$template = $this->getTemplate();
|
||||
|
||||
if (!$template) {
|
||||
throw new \ErrorException('Template is not set, cannot continue');
|
||||
}
|
||||
|
||||
// include files
|
||||
$files = isset($template->settings->files) ? $template->settings->files : [];
|
||||
|
||||
foreach ($files as $file) {
|
||||
include_once $file;
|
||||
}
|
||||
|
||||
// register templates
|
||||
$publicTemplates = call_user_func([$template->handler, 'getPublicTemplatePaths']);
|
||||
|
||||
if (!is_array($publicTemplates)) {
|
||||
throw new \ErrorException($template->handler . '::getPublicTemplatePaths() must return array!');
|
||||
}
|
||||
|
||||
if (empty($publicTemplates)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @var $registrator TemplateRegistrator
|
||||
*/
|
||||
$registrator = $this->app->make('registerTemplateDir');
|
||||
foreach ($publicTemplates as $template) {
|
||||
// setup some global variables
|
||||
$module = strtolower($template['module']);
|
||||
$namespace = isset($template['namespace']) ? $template['namespace'] : strtolower($template['module']);
|
||||
try {
|
||||
$registrator->setBaseDirectory('resources/views/modules/' . $module);
|
||||
$registrator->setNamespace($namespace);
|
||||
$registrator->setModuleId(call_user_func([config($module . '.handler'), 'getModuleId']));
|
||||
|
||||
// register path with current template name
|
||||
$registrator->register('visitor', $template['templateName']);
|
||||
} catch (InvalidArgumentException $e) {
|
||||
// ignore this exception
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Publish all public assets from all themes
|
||||
*/
|
||||
private function publishViewResources()
|
||||
{
|
||||
$template = $this->getTemplate();
|
||||
if (!$template) {
|
||||
return;
|
||||
}
|
||||
|
||||
$templateDir = app_path('../templates/' . $template->settings->staticName . '/Resources');
|
||||
$assetsDir = $templateDir . '/' . Template::ASSETS_DIRECTORY;
|
||||
$viewsDir = $templateDir . '/views';
|
||||
|
||||
// publish assets if exists for current theme
|
||||
if (is_dir($assetsDir)) {
|
||||
$this->publishes([$assetsDir => public_path('assets/visitor')], 'public-assets');
|
||||
}
|
||||
|
||||
// publish base visitors views
|
||||
$this->publishes([$viewsDir . '/visitor' => resource_path('views/visitor')], 'module-views');
|
||||
|
||||
// publish admin views
|
||||
if (is_dir($viewsDir . '/modules')) {
|
||||
$this->publishes([$viewsDir . '/modules' => resource_path('views/modules')], 'module-views');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user