added theme support
This commit is contained in:
@@ -7,11 +7,11 @@ use Modules\Stylist\Services\ThemeAccessibilityValidator;
|
|||||||
use Modules\Stylist\Services\ThemeSettings;
|
use Modules\Stylist\Services\ThemeSettings;
|
||||||
use Modules\Stylist\Theme\Stylist;
|
use Modules\Stylist\Theme\Stylist;
|
||||||
use Modules\Stylist\Theme\UrlGenerator;
|
use Modules\Stylist\Theme\UrlGenerator;
|
||||||
use Modules\Settings\Services\SettingsRepository;
|
use Modules\Stylist\Services\SiteSettingsRepository;
|
||||||
|
|
||||||
final class StylistController extends Controller
|
final class StylistController extends Controller
|
||||||
{
|
{
|
||||||
public function __invoke(Stylist $stylist, ThemeSettings $settings, ThemeAccessibilityValidator $accessibility, UrlGenerator $urls, SettingsRepository $siteSettings)
|
public function __invoke(Stylist $stylist, ThemeSettings $settings, ThemeAccessibilityValidator $accessibility, UrlGenerator $urls, SiteSettingsRepository $siteSettings)
|
||||||
{
|
{
|
||||||
return view('stylist::index', [
|
return view('stylist::index', [
|
||||||
'theme' => $stylist->current(), 'themes' => $stylist->all(), 'variables' => $stylist->variables(),
|
'theme' => $stylist->current(), 'themes' => $stylist->all(), 'variables' => $stylist->variables(),
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ namespace Modules\Stylist\Http\Controllers;
|
|||||||
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Routing\Controller;
|
use Illuminate\Routing\Controller;
|
||||||
use Modules\Settings\Services\SettingsRepository;
|
use Modules\Stylist\Services\SiteSettingsRepository;
|
||||||
use Modules\Stylist\Services\ThemeAccessibilityValidator;
|
use Modules\Stylist\Services\ThemeAccessibilityValidator;
|
||||||
use Modules\Stylist\Services\ThemeOptimizer;
|
use Modules\Stylist\Services\ThemeOptimizer;
|
||||||
use Modules\Stylist\Services\ThemePackageManager;
|
use Modules\Stylist\Services\ThemePackageManager;
|
||||||
@@ -14,7 +14,7 @@ use Modules\Stylist\View\ThemeViewResolver;
|
|||||||
|
|
||||||
final class ThemeManagementController extends Controller
|
final class ThemeManagementController extends Controller
|
||||||
{
|
{
|
||||||
public function activate(string $theme, Loader $loader, SettingsRepository $settings)
|
public function activate(string $theme, Loader $loader, SiteSettingsRepository $settings)
|
||||||
{
|
{
|
||||||
$item = $loader->find($theme);
|
$item = $loader->find($theme);
|
||||||
abort_unless(in_array($item->type(), ['frontend', 'backend'], true), 422, 'Only frontend and backend themes can be activated.');
|
abort_unless(in_array($item->type(), ['frontend', 'backend'], true), 422, 'Only frontend and backend themes can be activated.');
|
||||||
@@ -60,7 +60,7 @@ final class ThemeManagementController extends Controller
|
|||||||
{
|
{
|
||||||
$item = $loader->find($theme);
|
$item = $loader->find($theme);
|
||||||
abort_if(in_array($item->key(), ['sonardesk', 'sonardesk-admin'], true), 403, 'Bundled themes cannot be removed.');
|
abort_if(in_array($item->key(), ['sonardesk', 'sonardesk-admin'], true), 403, 'Bundled themes cannot be removed.');
|
||||||
$settings = app(SettingsRepository::class);
|
$settings = app(SiteSettingsRepository::class);
|
||||||
abort_if($settings->get($item->type().'_theme', null, 'site') === $item->key(), 409, 'Deactivate this theme before uninstalling.');
|
abort_if($settings->get($item->type().'_theme', null, 'site') === $item->key(), 409, 'Deactivate this theme before uninstalling.');
|
||||||
$packages->uninstall($item);
|
$packages->uninstall($item);
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ use Modules\Stylist\Services\ThemeSettings;
|
|||||||
use Modules\Stylist\Theme\Loader;
|
use Modules\Stylist\Theme\Loader;
|
||||||
use Modules\Stylist\Theme\Stylist;
|
use Modules\Stylist\Theme\Stylist;
|
||||||
|
|
||||||
use Modules\Settings\Services\SettingsRepository;
|
use Modules\Stylist\Services\SiteSettingsRepository;
|
||||||
|
|
||||||
final class StylistServiceProvider extends ServiceProvider
|
final class StylistServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
@@ -73,7 +73,7 @@ final class StylistServiceProvider extends ServiceProvider
|
|||||||
View::composer('stylist-theme-saasland::*', function ($view): void {
|
View::composer('stylist-theme-saasland::*', function ($view): void {
|
||||||
$theme = $this->app->make(Loader::class)->find('saasland');
|
$theme = $this->app->make(Loader::class)->find('saasland');
|
||||||
$settings = $this->app->make(ThemeSettings::class)->get($theme);
|
$settings = $this->app->make(ThemeSettings::class)->get($theme);
|
||||||
$siteSettings = $this->app->make(SettingsRepository::class)->site();
|
$siteSettings = $this->app->make(SiteSettingsRepository::class)->site();
|
||||||
$navigation = $this->app->make(FrontendNavigation::class);
|
$navigation = $this->app->make(FrontendNavigation::class);
|
||||||
$homepage = $this->app->make(FrontendContent::class)->homepage($settings);
|
$homepage = $this->app->make(FrontendContent::class)->homepage($settings);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,65 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\Stylist\Services;
|
||||||
|
|
||||||
|
use App\Models\SiteSetting;
|
||||||
|
|
||||||
|
final class SiteSettingsRepository
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Retrieve a SonarDesk site setting.
|
||||||
|
*
|
||||||
|
* The scope argument is retained for compatibility with Stylist.
|
||||||
|
*/
|
||||||
|
public function get(
|
||||||
|
string $key,
|
||||||
|
mixed $default = null,
|
||||||
|
string $scope = 'site'
|
||||||
|
): mixed {
|
||||||
|
$this->validateScope($scope);
|
||||||
|
|
||||||
|
$value = SiteSetting::valueFor($key);
|
||||||
|
|
||||||
|
return $value ?? $default;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Persist a SonarDesk site setting.
|
||||||
|
*
|
||||||
|
* The type and public arguments are retained for compatibility
|
||||||
|
* with Stylist's existing theme management API.
|
||||||
|
*/
|
||||||
|
public function put(
|
||||||
|
string $key,
|
||||||
|
mixed $value,
|
||||||
|
string $scope = 'site',
|
||||||
|
string $type = 'string',
|
||||||
|
bool $public = true
|
||||||
|
): void {
|
||||||
|
$this->validateScope($scope);
|
||||||
|
|
||||||
|
SiteSetting::put(
|
||||||
|
$key,
|
||||||
|
$value === null ? null : (string) $value
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return all site settings as an associative array.
|
||||||
|
*/
|
||||||
|
public function site(): array
|
||||||
|
{
|
||||||
|
return SiteSetting::query()
|
||||||
|
->pluck('value', 'key')
|
||||||
|
->all();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function validateScope(string $scope): void
|
||||||
|
{
|
||||||
|
if ($scope !== 'site') {
|
||||||
|
throw new \InvalidArgumentException(
|
||||||
|
"Unsupported settings scope: {$scope}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,11 +3,11 @@
|
|||||||
namespace Modules\Stylist\Services;
|
namespace Modules\Stylist\Services;
|
||||||
|
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
use Modules\Settings\Services\SettingsRepository;
|
use Modules\Stylist\Services\SiteSettingsRepository;
|
||||||
|
|
||||||
final class TenantThemeResolver
|
final class TenantThemeResolver
|
||||||
{
|
{
|
||||||
public function __construct(private readonly SettingsRepository $settings) {}
|
public function __construct(private readonly SiteSettingsRepository $settings) {}
|
||||||
|
|
||||||
public function resolve(?string $context = null): string
|
public function resolve(?string $context = null): string
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,13 +6,13 @@ use Illuminate\Filesystem\Filesystem;
|
|||||||
use Illuminate\Http\UploadedFile;
|
use Illuminate\Http\UploadedFile;
|
||||||
use Modules\Stylist\Theme\Loader;
|
use Modules\Stylist\Theme\Loader;
|
||||||
use Modules\Stylist\Theme\Theme;
|
use Modules\Stylist\Theme\Theme;
|
||||||
use Modules\Settings\Services\SettingsRepository;
|
use Modules\Stylist\Services\SiteSettingsRepository;
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
use ZipArchive;
|
use ZipArchive;
|
||||||
|
|
||||||
final class ThemePackageManager
|
final class ThemePackageManager
|
||||||
{
|
{
|
||||||
public function __construct(private readonly Filesystem $files, private readonly Loader $loader, private readonly ThemeValidator $validator, private readonly SettingsRepository $settings) {}
|
public function __construct(private readonly Filesystem $files, private readonly Loader $loader, private readonly ThemeValidator $validator, private readonly SiteSettingsRepository $settings) {}
|
||||||
|
|
||||||
public function install(UploadedFile $upload): Theme
|
public function install(UploadedFile $upload): Theme
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user