Gib dem Seiteneditor Kopf und Register des gemeinsamen Rahmens.
Dokument 12, CMS-R01: gemeinsamer Objektkopf mit getrennten Aussagen zu Speicherzustand („Änderungen nicht gespeichert“, „Entwurf gespeichert (Revision N)“, „Gespeicherter Stand ist veröffentlicht“) und öffentlicher Revision; „Seitenvorschau“, „Entwurf speichern“ (auch Strg+S) und „Veröffentlichen …“ im Kopf, „Live-Seite öffnen“ unter „Weitere Aktionen“. Register Seiteninhalt, Seiteneinstellungen und Verlauf (Revisionen). Ausgeblendete Register bleiben im Formularzustand und werden mitgespeichert; ein Fehler in einem ausgeblendeten Register zeigt dieses Register. „Nicht gespeichert“ vergleicht den normalisierten Editorstand mit dem geladenen Stand. Die Revisionsliste lädt sofort, weil das verzögerte Laden im ausgeblendeten Register nie ausgelöst würde. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b23b30e897
commit
aaad2fa19b
6 files changed
+291
-43
No files matched your search
@@ -38,11 +38,9 @@ public static function form(Schema $schema): Schema
|
||||
return $schema->components([
|
||||
Section::make('Seite und Suchmaschinen')
|
||||
->description('Adresse, Titel für Suchmaschinen und Zuordnung zu Themenbereichen.')
|
||||
->collapsible()
|
||||
->collapsed(fn (string $operation): bool => $operation === 'edit')
|
||||
->persistCollapsed()
|
||||
->columns(2)
|
||||
->columnSpanFull()
|
||||
->extraAttributes(fn ($livewire): array => ['class' => self::registerClass($livewire, 'einstellungen')])
|
||||
->schema([
|
||||
TextInput::make('path')
|
||||
->label('Pfad')
|
||||
@@ -65,13 +63,22 @@ public static function form(Schema $schema): Schema
|
||||
Section::make('Inhalt der Seite')
|
||||
->description('Abschnitt hinzufügen, Raster wählen, Widgets in die Plätze einsetzen. Ein Klick auf die Vorschau eines Widgets öffnet seinen Dialog; Hintergrund, Breite, Abstand und Trenner stehen unter „Gestaltung des Abschnitts“. Speichern legt einen Entwurf an; veröffentlicht wird erst über „Veröffentlichen“.')
|
||||
->columnSpanFull()
|
||||
->extraAttributes(['class' => 'luf-page-content'])
|
||||
->extraAttributes(fn ($livewire): array => ['class' => 'luf-page-content '.self::registerClass($livewire, 'inhalt')])
|
||||
->schema([
|
||||
SectionEditor::repeater('sections'),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Im Seiten-Arbeitsplatz (EditPage) zeigt jedes Register nur seinen Teil; ausgeblendete Felder bleiben im
|
||||
* Formularzustand und werden mitgespeichert. Beim Anlegen ist alles sichtbar.
|
||||
*/
|
||||
public static function registerClass(mixed $livewire, string $register): string
|
||||
{
|
||||
return is_object($livewire) && property_exists($livewire, 'register') && $livewire->register !== $register ? 'vw-ausgeblendet' : '';
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
|
||||
@@ -11,9 +11,13 @@
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
use Filament\Schemas\Components\Group;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Enums\Width;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Livewire\Attributes\Url;
|
||||
|
||||
class EditPage extends EditRecord
|
||||
{
|
||||
@@ -27,50 +31,128 @@ class EditPage extends EditRecord
|
||||
/** Warnt vor dem Verlassen oder Neuladen, wenn Änderungen noch nicht gespeichert sind. */
|
||||
protected ?bool $hasUnsavedDataChangesAlert = true;
|
||||
|
||||
/** Register des Seiten-Arbeitsplatzes: inhalt, einstellungen, verlauf (Dokument 12, CMS-R01). */
|
||||
#[Url(as: 'bereich', except: 'inhalt')]
|
||||
public string $register = 'inhalt';
|
||||
|
||||
/** Fingerabdruck des zuletzt geladenen oder gespeicherten Stands; Grundlage für „nicht gespeichert“. */
|
||||
public string $gespeicherterStand = '';
|
||||
|
||||
public function showRegister(string $register): void
|
||||
{
|
||||
$this->register = in_array($register, ['inhalt', 'einstellungen', 'verlauf'], true) ? $register : 'inhalt';
|
||||
}
|
||||
|
||||
/**
|
||||
* Gemeinsamer Objektkopf statt Filaments Titel, Pfad und Kopfaktionen.
|
||||
*/
|
||||
public function getHeader(): ?View
|
||||
{
|
||||
return view('filament.cms.seite-kopf', ['seite' => $this->record, 'ungespeichert' => $this->hasUnsavedEditorChanges()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Weicht der Editorstand vom geladenen oder gespeicherten Stand ab? Verglichen wird derselbe normalisierte
|
||||
* Zustand, der auch gespeichert würde; Vorschaubreiten zählen nicht.
|
||||
*/
|
||||
public function hasUnsavedEditorChanges(): bool
|
||||
{
|
||||
return $this->gespeicherterStand !== '' && $this->editorFingerprint() !== $this->gespeicherterStand;
|
||||
}
|
||||
|
||||
protected function afterFill(): void
|
||||
{
|
||||
$this->gespeicherterStand = $this->editorFingerprint();
|
||||
}
|
||||
|
||||
private function editorFingerprint(): string
|
||||
{
|
||||
$data = is_array($this->data ?? null) ? $this->data : [];
|
||||
$pillars = array_map('intval', (array) ($data['pillars'] ?? []));
|
||||
sort($pillars);
|
||||
|
||||
return md5(json_encode([
|
||||
self::withoutPreviewKeys(SectionEditor::fromEditorState(is_array($data['sections'] ?? null) ? $data['sections'] : [])),
|
||||
(string) ($data['path'] ?? ''),
|
||||
(string) ($data['seo_title'] ?? ''),
|
||||
(string) ($data['seo_description'] ?? ''),
|
||||
$pillars,
|
||||
], JSON_UNESCAPED_UNICODE) ?: '');
|
||||
}
|
||||
|
||||
private static function withoutPreviewKeys(mixed $value): mixed
|
||||
{
|
||||
if (! is_array($value)) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
unset($value['_preview_width']);
|
||||
|
||||
return array_map(self::withoutPreviewKeys(...), $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formular und Verlauf (Revisionen) als Register; ausgeblendete Teile bleiben im Formularzustand.
|
||||
*/
|
||||
public function content(Schema $schema): Schema
|
||||
{
|
||||
return $schema->components([
|
||||
$this->getFormContentComponent(),
|
||||
Group::make([$this->getRelationManagersContentComponent()])
|
||||
->extraAttributes(fn (): array => ['class' => $this->register === 'verlauf' ? '' : 'vw-ausgeblendet']),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Speichern steht im Kopf; die Leiste unter dem Formular entfällt.
|
||||
*/
|
||||
protected function getFormActions(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Ein Fehler in einem gerade ausgeblendeten Register zeigt dieses Register.
|
||||
*/
|
||||
public function save(bool $shouldRedirect = true, bool $shouldSendSavedNotification = true): void
|
||||
{
|
||||
try {
|
||||
parent::save($shouldRedirect, $shouldSendSavedNotification);
|
||||
} catch (ValidationException $exception) {
|
||||
$keys = implode(' ', array_keys($exception->errors()));
|
||||
$this->register = str_contains($keys, 'data.sections') ? 'inhalt' : (preg_match('/data\.(path|seo_|pillars)/', $keys) === 1 ? 'einstellungen' : $this->register);
|
||||
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('preview')
|
||||
->label('Vorschau')
|
||||
->icon('heroicon-o-device-phone-mobile')
|
||||
->color('gray')
|
||||
->tooltip('Zuletzt gespeicherten Entwurf in Smartphone-, Tablet- und Desktopbreite ansehen')
|
||||
->url(function (): string {
|
||||
$revision = $this->record->latestRevision;
|
||||
return [];
|
||||
}
|
||||
|
||||
return $revision === null
|
||||
? '#'
|
||||
: route('pages.preview.devices', $revision);
|
||||
})
|
||||
->openUrlInNewTab(),
|
||||
Action::make('publish')
|
||||
->label('Veröffentlichen')
|
||||
->icon('heroicon-o-globe-alt')
|
||||
->requiresConfirmation()
|
||||
->modalHeading('Seite veröffentlichen?')
|
||||
->modalDescription('Der aktuelle Stand im Editor wird als Entwurf gespeichert und genau dieser Stand wird veröffentlicht. Enthält er Fehler, wird nichts veröffentlicht.')
|
||||
->modalSubmitActionLabel('Speichern und veröffentlichen')
|
||||
->visible(fn (): bool => auth()->user()?->can('publish', $this->record) ?? false)
|
||||
->action(function (PageService $service): void {
|
||||
// Ungespeicherte Änderungen (zum Beispiel ein eben gewähltes Bild) gingen sonst beim Veröffentlichen verloren.
|
||||
$this->save(shouldRedirect: false, shouldSendSavedNotification: false);
|
||||
public function publishAction(): Action
|
||||
{
|
||||
return Action::make('publish')
|
||||
->label('Veröffentlichen')
|
||||
->icon('heroicon-o-globe-alt')
|
||||
->requiresConfirmation()
|
||||
->modalHeading('Seite veröffentlichen?')
|
||||
->modalDescription('Der aktuelle Stand im Editor wird als Entwurf gespeichert und genau dieser Stand wird veröffentlicht. Enthält er Fehler, wird nichts veröffentlicht.')
|
||||
->modalSubmitActionLabel('Speichern und veröffentlichen')
|
||||
->visible(fn (): bool => auth()->user()?->can('publish', $this->record) ?? false)
|
||||
->action(function (PageService $service): void {
|
||||
// Ungespeicherte Änderungen (zum Beispiel ein eben gewähltes Bild) gingen sonst beim Veröffentlichen verloren.
|
||||
$this->save(shouldRedirect: false, shouldSendSavedNotification: false);
|
||||
|
||||
$this->record->unsetRelation('latestRevision');
|
||||
$revision = $this->record->latestRevision;
|
||||
abort_if($revision === null, 404);
|
||||
$service->publish($this->record, $revision);
|
||||
$this->record->refresh();
|
||||
$this->record->unsetRelation('latestRevision');
|
||||
$revision = $this->record->latestRevision;
|
||||
abort_if($revision === null, 404);
|
||||
$service->publish($this->record, $revision);
|
||||
$this->record->refresh();
|
||||
|
||||
Notification::make()->title('Seite veröffentlicht')->success()->send();
|
||||
}),
|
||||
Action::make('open')
|
||||
->label('Live-Seite')
|
||||
->icon('heroicon-o-arrow-top-right-on-square')
|
||||
->color('gray')
|
||||
->visible(fn (): bool => $this->record->isPublished())
|
||||
->url(fn (): string => $this->record->publicUrl())
|
||||
->openUrlInNewTab(),
|
||||
];
|
||||
Notification::make()->title('Seite veröffentlicht')->success()->send();
|
||||
});
|
||||
}
|
||||
|
||||
protected function getSaveFormAction(): Action
|
||||
|
||||
@@ -17,6 +17,9 @@ class RevisionsRelationManager extends RelationManager
|
||||
|
||||
protected static ?string $title = 'Revisionen';
|
||||
|
||||
/** Steht im Register „Verlauf“ zunächst ausgeblendet; verzögertes Laden würde dort nie ausgelöst. */
|
||||
protected static ?bool $isLazyLoaded = false;
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
|
||||
Reference in new issue
Block a user