themes how part of site settings
This commit is contained in:
@@ -5,23 +5,25 @@ namespace Modules\Settings\Http\Controllers;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\View\View;
|
||||
use Modules\Settings\Services\SettingsRepository;
|
||||
use Modules\Stylist\Theme\Loader;
|
||||
|
||||
final class SettingController extends Controller
|
||||
{
|
||||
public function index(SettingsRepository $settings): View
|
||||
public function index(SettingsRepository $settings, Loader $themes): View
|
||||
{
|
||||
return view('settings::index', [
|
||||
'values' => $settings->site(),
|
||||
'sections' => $this->sections(),
|
||||
'sections' => $this->sections($themes),
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(Request $request, SettingsRepository $settings): RedirectResponse
|
||||
public function update(Request $request, SettingsRepository $settings, Loader $themes): RedirectResponse
|
||||
{
|
||||
$rules = [];
|
||||
foreach ($this->sections() as $fields) {
|
||||
foreach ($this->sections($themes) as $fields) {
|
||||
foreach ($fields as $key => $definition) {
|
||||
$rules["settings.$key"] = $definition['rules'];
|
||||
}
|
||||
@@ -32,17 +34,43 @@ final class SettingController extends Controller
|
||||
$settings->put($key, $value, 'site', 'string', true);
|
||||
}
|
||||
|
||||
return back()->with('status', 'Site settings saved. The frontend has been updated everywhere.');
|
||||
return back()->with('status', 'Site settings saved. The active frontend and backend themes have been updated.');
|
||||
}
|
||||
|
||||
/** @return array<string, array<string, array<string, mixed>>> */
|
||||
private function sections(): array
|
||||
private function sections(Loader $themes): array
|
||||
{
|
||||
$text = ['type' => 'text', 'rules' => ['nullable', 'string', 'max:255']];
|
||||
$url = ['type' => 'text', 'rules' => ['nullable', 'string', 'max:2048'], 'placeholder' => '/path or https://example.com'];
|
||||
$textarea = ['type' => 'textarea', 'rules' => ['nullable', 'string', 'max:5000']];
|
||||
|
||||
$backendThemes = $themes->all()
|
||||
->filter(fn ($theme): bool => $theme->type() === 'backend')
|
||||
->mapWithKeys(fn ($theme): array => [$theme->key() => $theme->name()])
|
||||
->all();
|
||||
|
||||
$frontendThemes = $themes->all()
|
||||
->filter(fn ($theme): bool => $theme->type() === 'frontend')
|
||||
->mapWithKeys(fn ($theme): array => [$theme->key() => $theme->name()])
|
||||
->all();
|
||||
|
||||
return [
|
||||
'Themes' => [
|
||||
'backend_theme' => [
|
||||
'type' => 'select',
|
||||
'rules' => ['required', 'string', Rule::in(array_keys($backendThemes))],
|
||||
'label' => 'Backend theme',
|
||||
'help' => 'Used for the authenticated administration area.',
|
||||
'options' => $backendThemes,
|
||||
],
|
||||
'frontend_theme' => [
|
||||
'type' => 'select',
|
||||
'rules' => ['required', 'string', Rule::in(array_keys($frontendThemes))],
|
||||
'label' => 'Frontend theme',
|
||||
'help' => 'Used for the public website.',
|
||||
'options' => $frontendThemes,
|
||||
],
|
||||
],
|
||||
'General' => [
|
||||
'site_name' => $text + ['label' => 'Site name', 'help' => 'Used in the header, footer, browser titles and metadata.'],
|
||||
'tagline' => $text + ['label' => 'Tagline'],
|
||||
|
||||
Reference in New Issue
Block a user