Dieselbe Liste trägt die öffentliche Seite. Medien bleiben privat, Seiten können mehreren Säulen zugeordnet sein. Co-authored-by: Cursor <cursoragent@cursor.com>
140 lines
6.0 KiB
PHP
140 lines
6.0 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\Pages;
|
|
|
|
use App\Domain\Catalog\Pillar;
|
|
use App\Domain\Cms\Blocks\BlockRegistry;
|
|
use App\Domain\Cms\Page;
|
|
use App\Filament\Resources\Pages\Pages\CreatePage;
|
|
use App\Filament\Resources\Pages\Pages\EditPage;
|
|
use App\Filament\Resources\Pages\Pages\ListPages;
|
|
use App\Filament\Resources\Pages\RelationManagers\RevisionsRelationManager;
|
|
use Filament\Forms\Components\CheckboxList;
|
|
use Filament\Forms\Components\FileUpload;
|
|
use Filament\Forms\Components\Repeater;
|
|
use Filament\Forms\Components\Select;
|
|
use Filament\Forms\Components\Textarea;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Resources\Resource;
|
|
use Filament\Schemas\Components\Utilities\Get;
|
|
use Filament\Schemas\Schema;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Filament\Tables\Table;
|
|
|
|
class PageResource extends Resource
|
|
{
|
|
protected static ?string $model = Page::class;
|
|
|
|
protected static ?string $navigationLabel = 'Seiten';
|
|
|
|
protected static ?string $modelLabel = 'Seite';
|
|
|
|
protected static ?string $pluralModelLabel = 'Seiten';
|
|
|
|
protected static ?string $recordTitleAttribute = 'path';
|
|
|
|
public static function form(Schema $schema): Schema
|
|
{
|
|
$labels = app(BlockRegistry::class)->labels();
|
|
|
|
return $schema->components([
|
|
TextInput::make('path')
|
|
->label('Pfad')
|
|
->required()
|
|
->maxLength(255)
|
|
->helperText('Zum Beispiel / oder /praevention'),
|
|
TextInput::make('seo_title')
|
|
->label('SEO-Titel')
|
|
->maxLength(255),
|
|
Textarea::make('seo_description')
|
|
->label('SEO-Beschreibung')
|
|
->maxLength(500)
|
|
->columnSpanFull(),
|
|
CheckboxList::make('pillars')
|
|
->label('Fachliche Säulen')
|
|
->options(fn (): array => Pillar::query()->orderBy('name')->pluck('name', 'id')->all())
|
|
->helperText('Eine veröffentlichte Seite erscheint auf den gewählten Themenbereichen der Website. Eine Seite kann mehreren Säulen zugeordnet sein.')
|
|
->columns(1),
|
|
Repeater::make('blocks')
|
|
->label('Bausteine')
|
|
->schema([
|
|
Select::make('type')
|
|
->label('Typ')
|
|
->options($labels)
|
|
->required()
|
|
->live(),
|
|
TextInput::make('heading')
|
|
->label('Überschrift')
|
|
->visible(fn (Get $get): bool => in_array($get('type'), ['heading', 'call_to_action'], true)),
|
|
Textarea::make('intro')
|
|
->label('Einleitung')
|
|
->visible(fn (Get $get): bool => $get('type') === 'heading'),
|
|
Textarea::make('body')
|
|
->label('Text')
|
|
->visible(fn (Get $get): bool => in_array($get('type'), ['prose', 'image_text'], true))
|
|
->columnSpanFull(),
|
|
FileUpload::make('image')
|
|
->label('Bild')
|
|
->disk('cms_incoming')
|
|
->directory('cms')
|
|
->image()
|
|
->visible(fn (Get $get): bool => $get('type') === 'image_text'),
|
|
TextInput::make('alt')
|
|
->label('Alternativtext')
|
|
->visible(fn (Get $get): bool => $get('type') === 'image_text'),
|
|
Textarea::make('text')
|
|
->label('Text')
|
|
->visible(fn (Get $get): bool => $get('type') === 'call_to_action'),
|
|
TextInput::make('label')
|
|
->label('Beschriftung der Aktion')
|
|
->visible(fn (Get $get): bool => $get('type') === 'call_to_action'),
|
|
TextInput::make('url')
|
|
->label('Adresse')
|
|
->visible(fn (Get $get): bool => $get('type') === 'call_to_action'),
|
|
Repeater::make('items')
|
|
->label('Einträge')
|
|
->visible(fn (Get $get): bool => in_array($get('type'), ['cards', 'faq'], true))
|
|
->schema([
|
|
TextInput::make('title')->label('Titel')->visible(fn (Get $get): bool => $get('../../type') === 'cards'),
|
|
Textarea::make('text')->label('Text')->visible(fn (Get $get): bool => $get('../../type') === 'cards'),
|
|
TextInput::make('url')->label('Adresse')->visible(fn (Get $get): bool => $get('../../type') === 'cards'),
|
|
TextInput::make('question')->label('Frage')->visible(fn (Get $get): bool => $get('../../type') === 'faq'),
|
|
Textarea::make('answer')->label('Antwort')->visible(fn (Get $get): bool => $get('../../type') === 'faq'),
|
|
]),
|
|
])
|
|
->columnSpanFull()
|
|
->reorderable()
|
|
->collapsed(),
|
|
]);
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->columns([
|
|
TextColumn::make('path')->label('Pfad')->searchable(),
|
|
TextColumn::make('published_revision_id')
|
|
->label('Veröffentlicht')
|
|
->formatStateUsing(fn ($state): string => $state ? 'Ja' : 'Entwurf'),
|
|
TextColumn::make('updated_at')->label('Geändert')->dateTime('d.m.Y H:i'),
|
|
])
|
|
->recordUrl(fn (Page $record): string => static::getUrl('edit', ['record' => $record]));
|
|
}
|
|
|
|
public static function getRelations(): array
|
|
{
|
|
return [
|
|
RevisionsRelationManager::class,
|
|
];
|
|
}
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => ListPages::route('/'),
|
|
'create' => CreatePage::route('/create'),
|
|
'edit' => EditPage::route('/{record}/edit'),
|
|
];
|
|
}
|
|
}
|