Files
fewo-stommer/app/Filament/Pages/EditContent.php
T
Lars StommerandClaude Opus 5.5 82698f8eda Admin accounts with simple/expert mode, blocked periods list, brand assets, decisions
- Per-user admin mode (simple: bookings/contracts, blocked periods, guests, portal tasks,
  reviews; expert: everything the role allows), user menu switch, FollowsAdminMode on all
  resources/pages (guarded by a test); roles keep deciding permissions.
- Users list shows mode and 2FA; admins can reset another user's 2FA.
- New "Sperrzeiten" list for all apartments (manual blocks editable, portal blocks read-only).
- styles/final: clean hand-built SVG mark, logo, favicon (dark-mode aware), 4 icons, wave
  divider, plus PNG/WebP for mail/PDF/touch icon; colours via --brand-* variables.
- Decisions recorded in KONZEPT §6a/6b (booking path 1 via offer + guest acceptance, direct
  booking later; tourist tax by Ferienservice Balu); agent documents added and marked as
  analysis with assumptions; styles excluded from the deploy package.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 21:08:09 +02:00

142 lines
4.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Filament\Pages;
use App\Enums\UserRole;
use App\Filament\Concerns\FollowsAdminMode;
use App\Filament\Forms\Components\PhotoSelect;
use App\Support\Content;
use BackedEnum;
use Filament\Actions\Action;
use Filament\Forms\Components\RichEditor;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Notifications\Notification;
use Filament\Pages\Page;
use Filament\Schemas\Components\Actions;
use Filament\Schemas\Components\EmbeddedSchema;
use Filament\Schemas\Components\Form;
use Filament\Schemas\Components\Tabs;
use Filament\Schemas\Components\Tabs\Tab;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;
use UnitEnum;
/**
* One form for all editable website texts from config/content.php, one tab per section.
*
* @property-read Schema $form
*/
class EditContent extends Page
{
use FollowsAdminMode;
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedPencilSquare;
protected static string|UnitEnum|null $navigationGroup = 'Webseite';
protected static ?string $navigationLabel = 'Texte';
protected static ?string $title = 'Webseiten-Texte';
protected static ?string $slug = 'texte';
protected static ?int $navigationSort = 3;
/** @var array<string, ?string> */
public array $data = [];
public static function canAccess(): bool
{
return (bool) auth()->user()?->hasRole(UserRole::Admin, UserRole::Content);
}
public function mount(): void
{
$values = [];
foreach (Content::sections() as $section) {
foreach (array_keys($section['fields']) as $key) {
$values[self::fieldName($key)] = Content::get($key);
}
}
$this->form->fill($values);
}
public function form(Schema $schema): Schema
{
return $schema
->statePath('data')
->components([
Tabs::make('sections')
->persistTabInQueryString()
->tabs(collect(Content::sections())
->map(fn (array $section): Tab => Tab::make($section['label'])->schema(
collect($section['fields'])->map(fn (array $field, string $key) => $this->field($key, $field))->values()->all(),
))
->values()
->all()),
]);
}
public function content(Schema $schema): Schema
{
return $schema->components([
Form::make([EmbeddedSchema::make('form')])
->id('form')
->livewireSubmitHandler('save')
->footer([
Actions::make([
Action::make('save')->label('Speichern')->submit('save')->keyBindings(['mod+s']),
])->sticky(),
]),
]);
}
public function save(): void
{
$state = $this->form->getState();
$values = [];
foreach (Content::sections() as $section) {
foreach (array_keys($section['fields']) as $key) {
$value = $state[self::fieldName($key)] ?? null;
$values[$key] = $value === null ? null : (string) $value;
}
}
Content::save($values);
Notification::make()->title('Texte gespeichert')->success()->send();
}
/**
* @param array{label: string, type: string, default?: ?string} $field
*/
private function field(string $key, array $field): TextInput|Textarea|RichEditor|Select
{
$name = self::fieldName($key);
return match ($field['type']) {
'textarea' => Textarea::make($name)->label($field['label'])->rows(3),
'richtext' => RichEditor::make($name)
->label($field['label'])
->toolbarButtons([['bold', 'italic', 'link'], ['h2', 'h3'], ['bulletList', 'orderedList'], ['undo', 'redo']]),
'photo' => PhotoSelect::make($name)
->label($field['label'])
->placeholder('Kein Bild gewählt')
->helperText('Bilder verwalten Sie unter „Webseite › Bilder“.'),
default => TextInput::make($name)->label($field['label'])->maxLength(255),
};
}
/**
* Dots would be read as nested state, so content keys are flattened for the form.
*/
private static function fieldName(string $key): string
{
return str_replace('.', '__', $key);
}
}