Files
laraundfelix/app/Filament/Resources/Pages/Pages/CreatePage.php
T
LarsandClaude Opus 5.5 75596bdaec Führe Bausteine ohne Zwischenschritt und wähle CMS-Bilder im gemeinsamen Picker
- Bausteindialog: „Zum Seitenaufbau“ kehrt an die Stelle zurück, „Entwurf
  speichern“ übernimmt und speichert direkt; Fehler erscheinen wie beim Kopf.
- Karten mit Fachobjekt: zentrale Angaben aus der Redaktion als Platzhalter,
  eigene Angaben als „Eigene Angabe für diese Karte“ markiert.
- Bildfelder des CMS (Bausteine und Abschnittshintergrund) öffnen den
  gemeinsamen visuellen Picker statt einer eigenen Auswahlliste. Der allgemeine
  Teil des Pickers liegt im Trait ChoosesMedia (aus der Redaktion herausgelöst,
  nicht kopiert); ChoosesWebsiteImages übernimmt nur Website-Bilder in genau
  das auslösende Feld, auch im Bausteindialog. Keine Freigabe durch Auswahl.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 16:46:29 +01:00

80 lines
2.6 KiB
PHP

<?php
namespace App\Filament\Resources\Pages\Pages;
use App\Domain\Catalog\PillarService;
use App\Domain\Cms\Page;
use App\Domain\Cms\PageService;
use App\Filament\Resources\Pages\PageResource;
use App\Filament\Support\ChoosesWebsiteImages;
use App\Filament\Support\ReportsSectionErrors;
use App\Filament\Support\SectionEditor;
use Filament\Resources\Pages\CreateRecord;
use Filament\Support\Enums\Width;
use Illuminate\Contracts\View\View;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
use Illuminate\Validation\ValidationException;
class CreatePage extends CreateRecord
{
use ChoosesWebsiteImages;
use ReportsSectionErrors;
protected static string $resource = PageResource::class;
/** Breite Arbeitsfläche, damit mehrspaltige Raster im Editor erkennbar bleiben. */
protected Width|string|null $maxContentWidth = Width::Full;
/** Warnt vor dem Verlassen oder Neuladen, wenn Änderungen noch nicht gespeichert sind. */
protected ?bool $hasUnsavedDataChangesAlert = true;
protected static bool $canCreateAnother = false;
/** Gemeinsamer Bild-Picker über dem Formular und dem Bausteindialog. */
public function getFooter(): ?View
{
return view('filament.cms.bild-picker');
}
/**
* @param array<string, mixed> $data
*/
protected function handleRecordCreation(array $data): Model
{
$service = app(PageService::class);
$content = SectionEditor::fromEditorState($data['sections'] ?? []);
try {
return DB::transaction(function () use ($service, $data, $content): Page {
$page = Page::query()->create([
'path' => $service->availablePath($data['path']),
]);
$service->saveRevision(
$page,
$content,
$data['seo_title'] ?? null,
$data['seo_description'] ?? null,
auth()->user(),
);
app(PillarService::class)->assignPages($page, array_map(intval(...), $data['pillars'] ?? []));
return $page;
});
} catch (ValidationException $exception) {
SectionEditor::notifyErrors($exception->errors(), $this->data['sections'] ?? []);
throw ValidationException::withMessages(
SectionEditor::mapErrors($exception->errors(), $this->data['sections'] ?? []),
);
}
}
protected function getRedirectUrl(): string
{
return static::getResource()::getUrl('edit', ['record' => $this->getRecord()]);
}
}