From 75596bdaecbf2a3f5f41e0cdbfe7507f67dd2c91 Mon Sep 17 00:00:00 2001 From: Lars Date: Fri, 20 Nov 2026 16:46:29 +0100 Subject: [PATCH] =?UTF-8?q?F=C3=BChre=20Bausteine=20ohne=20Zwischenschritt?= =?UTF-8?q?=20und=20w=C3=A4hle=20CMS-Bilder=20im=20gemeinsamen=20Picker?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- .../Cms/Widgets/Support/ImageRefFields.php | 14 +- .../Cms/Widgets/Types/PremiumCardWidget.php | 31 ++- .../Resources/Pages/Pages/CreatePage.php | 9 + .../Resources/Pages/Pages/EditPage.php | 19 ++ app/Filament/Support/ChoosesMedia.php | 207 ++++++++++++++++++ app/Filament/Support/ChoosesWebsiteImages.php | 132 +++++++++++ .../Support/ManagesEditorialSurface.php | 174 +-------------- app/Filament/Support/WidgetEditor.php | 15 +- .../views/filament/cms/bild-feld.blade.php | 23 ++ .../views/filament/cms/bild-picker.blade.php | 4 + .../views/filament/cms/seite-kopf.blade.php | 3 +- .../filament/verwaltung/picker.blade.php | 4 +- tests/Feature/CmsArbeitsplatzTest.php | 25 ++- tests/Feature/CmsWebsiteMediaTest.php | 48 ++++ 14 files changed, 520 insertions(+), 188 deletions(-) create mode 100644 app/Filament/Support/ChoosesMedia.php create mode 100644 app/Filament/Support/ChoosesWebsiteImages.php create mode 100644 resources/views/filament/cms/bild-feld.blade.php create mode 100644 resources/views/filament/cms/bild-picker.blade.php diff --git a/app/Domain/Cms/Widgets/Support/ImageRefFields.php b/app/Domain/Cms/Widgets/Support/ImageRefFields.php index ca47880..9cb7006 100644 --- a/app/Domain/Cms/Widgets/Support/ImageRefFields.php +++ b/app/Domain/Cms/Widgets/Support/ImageRefFields.php @@ -6,7 +6,7 @@ use Filament\Forms\Components\Field; use Filament\Forms\Components\FileUpload; use Filament\Forms\Components\Placeholder; -use Filament\Forms\Components\Select; +use Filament\Forms\Components\ViewField; use Filament\Notifications\Notification; use Filament\Schemas\Components\Utilities\Get; use Filament\Schemas\Components\Utilities\Set; @@ -34,16 +34,12 @@ final class ImageRefFields public static function fields(string $label = 'Bild', bool $live = false, string $key = 'image', ?string $altField = null): array { return [ - Select::make($key) + // Auswahl über den gemeinsamen visuellen Picker (Suche, Vorschau, Website-Freigabe im Detail). + ViewField::make($key) ->live() ->label($label.' aus dem Medienmanager') - ->searchable() - ->allowHtml() - ->options(fn (): array => app(WebsiteImage::class)->options()) - ->getSearchResultsUsing(fn (?string $search): array => app(WebsiteImage::class)->options($search)) - ->getOptionLabelUsing(fn (mixed $value): ?string => app(WebsiteImage::class)->optionHtml($value)) - ->placeholder('Kein Bild') - ->helperText('Alle Bilder des Medienmanagers. Öffentlich erscheint ein Bild nur mit Website-Freigabe.'), + ->view('filament.cms.bild-feld') + ->helperText('Öffentlich erscheint ein Bild nur mit Website-Freigabe; die Auswahl gibt es nicht frei.'), FileUpload::make('_upload') ->live() ->label($label.': neues Bild hochladen') diff --git a/app/Domain/Cms/Widgets/Types/PremiumCardWidget.php b/app/Domain/Cms/Widgets/Types/PremiumCardWidget.php index eb817d3..d6fc682 100644 --- a/app/Domain/Cms/Widgets/Types/PremiumCardWidget.php +++ b/app/Domain/Cms/Widgets/Types/PremiumCardWidget.php @@ -13,6 +13,8 @@ use Filament\Forms\Components\Select; use Filament\Forms\Components\TextInput; use Filament\Schemas\Components\Group; +use Filament\Schemas\Components\Utilities\Get; +use Illuminate\Support\Str; /** * Gemeinsame Basis der Premium-Karten (Brand-UI-Kit v1.7, Entwurf zur visuellen Freigabe): @@ -183,17 +185,22 @@ public function editorSchema(): array Group::make([ $action, $note, + // Zentrale Angaben aus der Redaktion als Platzhalter; eine eigene Eintragung ist als solche markiert. TextInput::make('heading') ->label('Anzeigename nur für diese Karte') ->maxLength(200) ->live(onBlur: true) - ->placeholder('Zentraler Anzeigename') + ->placeholder(fn (Get $get): string => $this->centralText($get('../refs.'.$this->refKey()), 'title') ?? 'Zentraler Anzeigename') + ->hint(fn (?string $state): string => filled($state) ? 'Eigene Angabe für diese Karte' : 'Aus der Redaktion') + ->hintColor(fn (?string $state): string => filled($state) ? 'warning' : 'gray') ->helperText('Leer übernimmt den Anzeigenamen des Fachobjekts. Eine Eintragung gilt nur für diese Karte und ändert die Quelle nicht.'), TextInput::make('summary') ->label('Teaser nur für diese Karte') ->maxLength(500) ->live(onBlur: true) - ->placeholder('Zentraler Teaser oder Kurzbeschreibung') + ->placeholder(fn (Get $get): string => $this->centralText($get('../refs.'.$this->refKey()), 'summary') ?? 'Zentraler Teaser oder Kurzbeschreibung') + ->hint(fn (?string $state): string => filled($state) ? 'Eigene Angabe für diese Karte' : 'Aus der Redaktion') + ->hintColor(fn (?string $state): string => filled($state) ? 'warning' : 'gray') ->helperText('Leer übernimmt Teaser oder Kurzbeschreibung. Lehrinhalt, Rechte und Preise bleiben unberührt.'), ])->statePath('data'), ]; @@ -292,6 +299,26 @@ protected function centralCoverId(mixed $id): ?int return null; } + /** + * Zentraler Anzeigename oder Teaser des gewählten Objekts (Redaktionsstand) für Platzhalter im Editor. + */ + private function centralText(mixed $id, string $field): ?string + { + if (blank($id)) { + return null; + } + + try { + $subject = $this->subject($id, RenderContext::preview()); + } catch (\Throwable) { + return null; + } + + $text = $subject?->{$field}; + + return is_string($text) && trim($text) !== '' ? Str::limit(trim($text), 120) : null; + } + private function subjectField(): Select { return Select::make($this->refKey()) diff --git a/app/Filament/Resources/Pages/Pages/CreatePage.php b/app/Filament/Resources/Pages/Pages/CreatePage.php index 9ae2927..e1bc637 100644 --- a/app/Filament/Resources/Pages/Pages/CreatePage.php +++ b/app/Filament/Resources/Pages/Pages/CreatePage.php @@ -6,16 +6,19 @@ 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; @@ -28,6 +31,12 @@ class CreatePage extends CreateRecord 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 $data */ diff --git a/app/Filament/Resources/Pages/Pages/EditPage.php b/app/Filament/Resources/Pages/Pages/EditPage.php index 0b34831..d610347 100644 --- a/app/Filament/Resources/Pages/Pages/EditPage.php +++ b/app/Filament/Resources/Pages/Pages/EditPage.php @@ -6,6 +6,7 @@ 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\Actions\Action; @@ -21,6 +22,7 @@ class EditPage extends EditRecord { + use ChoosesWebsiteImages; use ReportsSectionErrors; protected static string $resource = PageResource::class; @@ -212,6 +214,23 @@ private function showFailingSection(array $errorKeys): void $this->abschnitt = $design; } + /** + * „Entwurf speichern“ aus dem Bausteindialog: Der Baustein ist bereits übernommen, der Dialog schließt. Ein Fehler + * wird wie beim Speichern im Kopf gezeigt (Register, Abschnitt, Meldung), ohne den Baustein erneut zu öffnen. + */ + public function saveFromBlock(): void + { + try { + $this->save(shouldRedirect: false); + } catch (ValidationException $exception) { + foreach ($exception->errors() as $key => $messages) { + foreach ((array) $messages as $message) { + $this->addError($key, $message); + } + } + } + } + protected function getHeaderActions(): array { return []; diff --git a/app/Filament/Support/ChoosesMedia.php b/app/Filament/Support/ChoosesMedia.php new file mode 100644 index 0000000..5565112 --- /dev/null +++ b/app/Filament/Support/ChoosesMedia.php @@ -0,0 +1,207 @@ + Ziel => Titel; bleibt bei Suche und Filter erhalten */ + public array $pickerMarked = []; + + public string $presentationRole = 'titelbild'; + + public bool $bindToVersion = false; + + public ?string $replacingKey = null; + + abstract public function pickerAllowsMany(): bool; + + abstract public function closePicker(): void; + + abstract public function confirmPicker(): void; + + public function inspectPicker(string $target, bool $mark = false): void + { + $this->pickerInspected = $target; + + if ($mark) { + $this->markPicker($target, true); + } + } + + public function togglePick(string $target): void + { + $this->markPicker($target, ! isset($this->pickerMarked[$target])); + } + + public function markPicker(string $target, bool $on): void + { + if (! $on) { + unset($this->pickerMarked[$target]); + + if ($this->pickerSelected === $target) { + $this->pickerSelected = ''; + } + + return; + } + + $row = app(EditorialCatalog::class)->rowForTarget($target, $this->pickerExceptId(), allowDraft: true); + + if ($row === null) { + return; + } + + if (! $this->pickerAllowsMany()) { + $this->pickerMarked = []; + $this->pickerSelected = $target; + } + + $this->pickerMarked[$target] = (string) $row['title']; + + if ($this->pickerInspected === '') { + $this->pickerInspected = $target; + } + } + + /** + * @return array{items: list>, more: bool} + */ + public function pickerResult(): array + { + if (! $this->pickerOpen) { + return ['items' => [], 'more' => false]; + } + + if ($this->pickerPurpose === 'aufbau') { + return app(EditorialCatalog::class)->browse( + $this->pickerQuery, + $this->pickerKind, + $this->pickerDimension, + $this->pickerExceptId(), + ); + } + + $result = app(EditorialCatalog::class)->presentationBrowse($this->pickerQuery, $this->pickerKind); + + // CMS: nur Bilder, die als Website-Bild wählbar sind (keine vertraulichen Arten, nicht archiviert). + if ($this->pickerPurpose === 'website-bild') { + $ids = array_values(array_filter(array_map(fn (array $item): int => (int) ($item['element_id'] ?? 0), $result['items']))); + $elements = ContentElement::query()->with('editorialContentKind')->whereKey($ids)->get()->keyBy('id'); + $result['items'] = array_values(array_filter($result['items'], function (array $item) use ($elements): bool { + $element = $elements->get((int) ($item['element_id'] ?? 0)); + + return $element !== null && WebsiteImage::isSelectable($element); + })); + } + + return $result; + } + + /** + * @return array|null + */ + public function pickerDetail(): ?array + { + $target = $this->pickerInspected !== '' ? $this->pickerInspected : $this->pickerSelected; + + if ($target === '') { + return null; + } + + $row = app(EditorialCatalog::class)->rowForTarget($target, $this->pickerExceptId(), allowDraft: true); + + if ($row === null) { + return null; + } + + $row['playback'] = null; + $row['file_url'] = null; + $elementId = isset($row['element_id']) ? (int) $row['element_id'] : 0; + + if (preg_match('/^element:(\d+)$/', (string) $row['target'], $match) === 1) { + $version = ContentElementVersion::query()->with('element.editorialContentKind')->find($match[1]); + + if ($version instanceof ContentElementVersion) { + $row['playback'] = app(ContentPreviewController::class)->playback($version); + } + } + + $element = $elementId > 0 ? ContentElement::query()->with(['editorialContentKind', 'pillars'])->find($elementId) : null; + + if ($element instanceof ContentElement) { + $row['visibility'] = app(PublicMaterialReader::class)->visibilityNote($element); + $row['released'] = $element->website_released_at !== null; + $row['output_label'] = PublicMaterialReader::outputLabel((string) $element->output_class); + $row['pillars'] = $element->pillars->pluck('name')->all(); + $row['usage'] = app(CatalogReading::class)->elementUsage($element); + } + + return $row; + } + + /** + * @return list + */ + public function pickerVersions(): array + { + $detail = $this->pickerDetail(); + + if ($detail === null) { + return []; + } + + $options = app(EditorialCatalog::class)->alternatives((string) ($detail['identity'] ?? ''), $this->pickerExceptId()); + + if ($options === []) { + return []; + } + + $current = $options[array_key_last($options)]['target']; + + return array_map(fn (array $option): array => $option + ['current' => $option['target'] === $current], $options); + } + + protected function pickerExceptId(): int + { + return 0; + } + + protected function resetPicker(string $purpose): void + { + $this->pickerPurpose = $purpose; + $this->pickerOpen = true; + $this->pickerQuery = ''; + $this->pickerDimension = ''; + $this->pickerInspected = ''; + $this->pickerSelected = ''; + $this->pickerMarked = []; + $this->replacingKey = null; + $this->bindToVersion = false; + } +} diff --git a/app/Filament/Support/ChoosesWebsiteImages.php b/app/Filament/Support/ChoosesWebsiteImages.php new file mode 100644 index 0000000..790f088 --- /dev/null +++ b/app/Filament/Support/ChoosesWebsiteImages.php @@ -0,0 +1,132 @@ +resetPicker('website-bild'); + $this->pickerKind = 'bild'; + $this->bildZiel = $pfad; + $this->forceRenderForPicker(); + } + + /** + * Filament rendert bei offenen Aktionsdialogen nur den Dialogteil neu; der Picker liegt darüber und braucht die + * ganze Seite. + */ + public function hydrateChoosesWebsiteImages(): void + { + if ($this->pickerOpen) { + $this->forceRenderForPicker(); + } + } + + public function pickerAllowsMany(): bool + { + return false; + } + + public function closePicker(): void + { + $this->pickerOpen = false; + $this->pickerSelected = ''; + $this->pickerInspected = ''; + $this->pickerMarked = []; + $this->bildZiel = null; + $this->forceRenderForPicker(); + } + + public function confirmPicker(): void + { + $target = array_key_first($this->pickerMarked); + $ziel = $this->bildZiel; + + if ($target === null || $ziel === null) { + return; + } + + $row = app(EditorialCatalog::class)->rowForTarget((string) $target, 0, allowDraft: true); + $element = isset($row['element_id']) ? ContentElement::query()->find((int) $row['element_id']) : null; + + if (! $element instanceof ContentElement || ! WebsiteImage::isSelectable($element)) { + Notification::make()->danger()->title('Dieses Medium kann nicht als Website-Bild gewählt werden.')->send(); + + return; + } + + data_set($this, $ziel, $element->id); + $this->closePicker(); + } + + /** + * @return array + */ + public function pickerKinds(): array + { + return ['bild' => 'Bilder']; + } + + public function pickerTitle(): string + { + return 'Bild aus dem Medienmanager'; + } + + public function pickerConfirmLabel(): string + { + return 'Bild übernehmen'; + } + + /** + * @return array{art: string, titel: string} + */ + public function pickerKontext(): array + { + $pfad = property_exists($this, 'record') && is_object($this->record ?? null) ? (string) ($this->record->path ?? '') : ''; + + return ['art' => 'die Seite', 'titel' => $pfad !== '' ? $pfad : 'neue Seite']; + } + + /** + * @return array + */ + public function presentationRoleOptions(): array + { + return []; + } + + /** + * @return array|null + */ + public function pickerReplacing(): ?array + { + return null; + } + + private function forceRenderForPicker(): void + { + if (method_exists($this, 'forceRender')) { + $this->forceRender(); + } + } +} diff --git a/app/Filament/Support/ManagesEditorialSurface.php b/app/Filament/Support/ManagesEditorialSurface.php index 3e1bf87..0404cb7 100644 --- a/app/Filament/Support/ManagesEditorialSurface.php +++ b/app/Filament/Support/ManagesEditorialSurface.php @@ -11,10 +11,8 @@ use App\Domain\Catalog\EditorialTextVariant; use App\Domain\Catalog\PresentationMedia; use App\Domain\Catalog\PresentationRole; -use App\Domain\Cms\Catalog\PublicMaterialReader; use App\Domain\Media\WebsiteRelease; use App\Filament\Resources\ContentElements\ContentElementResource; -use App\Http\Controllers\ContentPreviewController; use App\Models\User; use Illuminate\Database\Eloquent\Model; use Livewire\Attributes\Url; @@ -31,6 +29,8 @@ */ trait ManagesEditorialSurface { + use ChoosesMedia; + /** Steht in der Adresse, damit „Zurück“ im Browser von der Redaktion in den Ausgangseditor führt. */ #[Url(as: 'redaktion', history: true)] public bool $redaktionOpen = false; @@ -65,29 +65,6 @@ trait ManagesEditorialSurface public bool $ausgabeOpen = false; - public bool $pickerOpen = false; - - public string $pickerPurpose = 'praesentation'; - - public string $pickerQuery = ''; - - public string $pickerKind = 'alle'; - - public string $pickerDimension = ''; - - public string $pickerInspected = ''; - - public string $pickerSelected = ''; - - /** @var array Ziel => Titel; bleibt bei Suche und Filter erhalten */ - public array $pickerMarked = []; - - public string $presentationRole = 'titelbild'; - - public bool $bindToVersion = false; - - public ?string $replacingKey = null; - /** @var array{aktion: string, argument: int|string|null, titel: string, text: string, label: string, gefahr: bool}|null */ public ?array $bestaetigung = null; @@ -614,50 +591,6 @@ public function closePicker(): void } } - public function inspectPicker(string $target, bool $mark = false): void - { - $this->pickerInspected = $target; - - if ($mark) { - $this->markPicker($target, true); - } - } - - public function togglePick(string $target): void - { - $this->markPicker($target, ! isset($this->pickerMarked[$target])); - } - - public function markPicker(string $target, bool $on): void - { - if (! $on) { - unset($this->pickerMarked[$target]); - - if ($this->pickerSelected === $target) { - $this->pickerSelected = ''; - } - - return; - } - - $row = app(EditorialCatalog::class)->rowForTarget($target, $this->pickerExceptId(), allowDraft: true); - - if ($row === null) { - return; - } - - if (! $this->pickerAllowsMany()) { - $this->pickerMarked = []; - $this->pickerSelected = $target; - } - - $this->pickerMarked[$target] = (string) $row['title']; - - if ($this->pickerInspected === '') { - $this->pickerInspected = $target; - } - } - public function pickerAllowsMany(): bool { return $this->pickerPurpose === 'praesentation' && $this->roleAllowsMany($this->presentationRole); @@ -741,91 +674,6 @@ public function assignFromPicker(string $target): void $this->confirmPicker(); } - /** - * @return array{items: list>, more: bool} - */ - public function pickerResult(): array - { - if (! $this->pickerOpen) { - return ['items' => [], 'more' => false]; - } - - if ($this->pickerPurpose === 'aufbau') { - return app(EditorialCatalog::class)->browse( - $this->pickerQuery, - $this->pickerKind, - $this->pickerDimension, - $this->pickerExceptId(), - ); - } - - return app(EditorialCatalog::class)->presentationBrowse($this->pickerQuery, $this->pickerKind); - } - - /** - * @return array|null - */ - public function pickerDetail(): ?array - { - $target = $this->pickerInspected !== '' ? $this->pickerInspected : $this->pickerSelected; - - if ($target === '') { - return null; - } - - $row = app(EditorialCatalog::class)->rowForTarget($target, $this->pickerExceptId(), allowDraft: true); - - if ($row === null) { - return null; - } - - $row['playback'] = null; - $row['file_url'] = null; - $elementId = isset($row['element_id']) ? (int) $row['element_id'] : 0; - - if (preg_match('/^element:(\d+)$/', (string) $row['target'], $match) === 1) { - $version = ContentElementVersion::query()->with('element.editorialContentKind')->find($match[1]); - - if ($version instanceof ContentElementVersion) { - $row['playback'] = app(ContentPreviewController::class)->playback($version); - } - } - - $element = $elementId > 0 ? ContentElement::query()->with(['editorialContentKind', 'pillars'])->find($elementId) : null; - - if ($element instanceof ContentElement) { - $row['visibility'] = app(PublicMaterialReader::class)->visibilityNote($element); - $row['released'] = $element->website_released_at !== null; - $row['output_label'] = PublicMaterialReader::outputLabel((string) $element->output_class); - $row['pillars'] = $element->pillars->pluck('name')->all(); - $row['usage'] = app(CatalogReading::class)->elementUsage($element); - } - - return $row; - } - - /** - * @return list - */ - public function pickerVersions(): array - { - $detail = $this->pickerDetail(); - - if ($detail === null) { - return []; - } - - $options = app(EditorialCatalog::class)->alternatives((string) ($detail['identity'] ?? ''), $this->pickerExceptId()); - - if ($options === []) { - return []; - } - - $current = $options[array_key_last($options)]['target']; - - return array_map(fn (array $option): array => $option + ['current' => $option['target'] === $current], $options); - } - /** * @return array */ @@ -893,24 +741,6 @@ public function pickerReplacing(): ?array return null; } - protected function pickerExceptId(): int - { - return 0; - } - - protected function resetPicker(string $purpose): void - { - $this->pickerPurpose = $purpose; - $this->pickerOpen = true; - $this->pickerQuery = ''; - $this->pickerDimension = ''; - $this->pickerInspected = ''; - $this->pickerSelected = ''; - $this->pickerMarked = []; - $this->replacingKey = null; - $this->bindToVersion = false; - } - protected function defaultKindForRole(string $role): string { return match ($role) { diff --git a/app/Filament/Support/WidgetEditor.php b/app/Filament/Support/WidgetEditor.php index 4af0122..7254bf4 100644 --- a/app/Filament/Support/WidgetEditor.php +++ b/app/Filament/Support/WidgetEditor.php @@ -95,9 +95,20 @@ public static function slotBuilder(string $name = 'widget'): Builder ->size('sm') ->color('gray') ->modalHeading(fn (Builder $component, array $arguments): string => self::configureHeading($component, (string) ($arguments['item'] ?? ''))) - ->modalDescription('Inhalt, Medien und Darstellung dieses Bausteins. „Zur Seite“ übernimmt die Eingaben in den Seitenentwurf; gespeichert wird über „Entwurf speichern“.') + ->modalDescription(fn ($livewire): string => method_exists($livewire, 'openAbschnitt') + ? 'Eingaben gelten im Seitenentwurf. „Zum Seitenaufbau“ kehrt an diese Stelle zurück, „Entwurf speichern“ sichert zusätzlich die Seite.' + : 'Eingaben gelten im Entwurf der neuen Seite.') ->modalWidth(Width::Screen) - ->modalSubmitActionLabel('Zur Seite') + ->modalSubmitActionLabel('Zum Seitenaufbau') + // Kein Zwischenschritt: Speichern geht direkt aus dem Baustein (übernimmt und speichert den Entwurf). + ->extraModalFooterActions(fn (Action $action, $livewire): array => method_exists($livewire, 'saveFromBlock') + ? [$action->makeModalSubmitAction('entwurfSpeichern', arguments: ['speichern' => true])->label('Entwurf speichern')->color('gray')] + : []) + ->after(function (array $arguments, $livewire): void { + if (($arguments['speichern'] ?? false) && method_exists($livewire, 'saveFromBlock')) { + $livewire->saveFromBlock(); + } + }) ->modalCancelActionLabel('Änderungen verwerfen') ->closeModalByClickingAway(false) ->closeModalByEscaping(false) diff --git a/resources/views/filament/cms/bild-feld.blade.php b/resources/views/filament/cms/bild-feld.blade.php new file mode 100644 index 0000000..7e72d96 --- /dev/null +++ b/resources/views/filament/cms/bild-feld.blade.php @@ -0,0 +1,23 @@ +{{-- Bildfeld im CMS: Auswahl über den gemeinsamen Picker (ChoosesWebsiteImages); Status zeigt das Feld „Gewähltes Bild“. --}} +@php + $wert = $getState(); + $pfad = $getStatePath(); + $mitPicker = method_exists($getLivewire(), 'openWebsiteImagePicker'); +@endphp + +
+ @if (blank($wert)) + Kein Bild gewählt. + @endif + @if ($mitPicker) + + {{ blank($wert) ? 'Bild auswählen' : 'Anderes Bild wählen' }} + + @endif + @if (filled($wert)) + + Bild entfernen + + @endif +
+
diff --git a/resources/views/filament/cms/bild-picker.blade.php b/resources/views/filament/cms/bild-picker.blade.php new file mode 100644 index 0000000..c135e31 --- /dev/null +++ b/resources/views/filament/cms/bild-picker.blade.php @@ -0,0 +1,4 @@ +{{-- Gemeinsamer Picker für Website-Bilder im CMS (ChoosesWebsiteImages). --}} +@if ($this->pickerOpen && $this->pickerPurpose === 'website-bild') + @include('filament.verwaltung.picker') +@endif diff --git a/resources/views/filament/cms/seite-kopf.blade.php b/resources/views/filament/cms/seite-kopf.blade.php index 5ace50e..7cbe42c 100644 --- a/resources/views/filament/cms/seite-kopf.blade.php +++ b/resources/views/filament/cms/seite-kopf.blade.php @@ -74,7 +74,7 @@ $abschnittsZustand = $this->data['sections'][$abschnittSchluessel] ?? []; $rasterKurz = \App\Domain\Cms\Sections\SectionLayouts::short(\App\Domain\Cms\Sections\SectionLayouts::has($abschnittsZustand['layout'] ?? null) ? $abschnittsZustand['layout'] : \App\Domain\Cms\Sections\SectionLayouts::DEFAULT); @endphp -
+

Abschnitt {{ $this->abschnitt + 1 }} gestalten

Raster {{ $rasterKurz }} @@ -105,3 +105,4 @@ .fi-grid-col:has(> .fi-sc-component > .vw-ausgeblendet) { display: none; } .fi-page-header-main-ctn { row-gap: 0.5rem; } +@include('filament.cms.bild-picker') diff --git a/resources/views/filament/verwaltung/picker.blade.php b/resources/views/filament/verwaltung/picker.blade.php index 1fa8582..09b32a8 100644 --- a/resources/views/filament/verwaltung/picker.blade.php +++ b/resources/views/filament/verwaltung/picker.blade.php @@ -7,7 +7,7 @@ $markiert = $this->pickerMarked; $ersetzt = $this->replacingKey !== null ? $this->pickerReplacing() : null; $rollen = $this->presentationRoleOptions(); - $bindbar = $zweck !== 'aufbau' && in_array($this->presentationRole, \App\Domain\Catalog\PresentationRole::BOUND_ROLES, true); + $bindbar = in_array($zweck, ['praesentation', 'austausch'], true) && in_array($this->presentationRole, \App\Domain\Catalog\PresentationRole::BOUND_ROLES, true); $symbol = fn (?string $output): string => match ($output) { 'film' => 'film', 'bild' => 'bild', 'audio' => 'audio', default => 'dokument' }; $kopf = $this->pickerKontext(); @endphp @@ -217,6 +217,8 @@ @if ($ersetzt) {{ $zweck === 'praesentation' ? 'Diese Rolle hat nur ein Medium. ' : '' }}Erst „Austauschen“ ersetzt die Zuordnung an derselben Stelle. Abbrechen lässt sie unverändert. + @elseif ($zweck === 'website-bild') + Das gewählte Bild wird in diesen Platz des Seitenentwurfs übernommen. Öffentlich erscheint es nur mit Website-Freigabe; die Auswahl gibt es nicht frei. @elseif ($zweck === 'vorschaubild') Das gewählte Bild wird als Vorschaubild übernommen. Es wird dadurch nicht für die Website freigegeben. @elseif ($zweck === 'aufbau') diff --git a/tests/Feature/CmsArbeitsplatzTest.php b/tests/Feature/CmsArbeitsplatzTest.php index eb89708..6acd275 100644 --- a/tests/Feature/CmsArbeitsplatzTest.php +++ b/tests/Feature/CmsArbeitsplatzTest.php @@ -163,13 +163,36 @@ public function test_configuring_a_block_names_it_and_its_place_and_returns_to_t $component->assertSee('Konfigurieren')->mountAction($edit); $action = $component->instance()->getMountedAction(); $this->assertSame('Überschrift und Einleitung konfigurieren · Abschnitt 1 · Platz 1 · 4 Einheiten', $action->getModalHeading()); - $this->assertSame('Zur Seite', $action->getModalSubmitActionLabel()); + $this->assertSame('Zum Seitenaufbau', $action->getModalSubmitActionLabel()); + $this->assertSame(['entwurfSpeichern'], array_values(array_map(fn ($footer) => $footer->getName(), $action->getExtraModalFooterActions()))); $this->assertFalse($action->isModalClosedByEscaping()); $this->assertFalse($action->isModalClosedByClickingAway()); $this->assertFalse($action->hasModalCloseButton(), 'Ohne Schließen-Kreuz: Verlassen nur über „Zur Seite“ oder „Änderungen verwerfen“.'); $this->assertStringContainsString('luf-baustein-dialog', (string) $action->getExtraModalWindowAttributeBag(), 'Eigener Scrollbereich, damit der Dialogfuß erreichbar bleibt.'); } + public function test_saving_from_the_block_applies_it_and_saves_the_draft_without_an_extra_step(): void + { + $page = Page::query()->where('path', '/praevention')->firstOrFail(); + $before = $page->latestRevision->id; + $component = Livewire::actingAs($this->editor(), 'staff')->test(EditPage::class, ['record' => $page->id]); + $sectionKey = array_key_first($component->get('data.sections')); + $slotKey = array_key_first($component->get("data.sections.$sectionKey.slots")); + $widgetKey = array_key_first($component->get("data.sections.$sectionKey.slots.$slotKey.widget")); + $data = $component->get("data.sections.$sectionKey.slots.$slotKey.widget.$widgetKey.data"); + $data['data']['heading'] = 'Direkt aus dem Baustein gespeichert'; + + $component->callAction( + TestAction::make('edit')->schemaComponent("sections.$sectionKey.slots.$slotKey.widget")->arguments(['item' => $widgetKey, 'speichern' => true]), + $data, + )->assertHasNoErrors(); + + $revision = $page->fresh()->latestRevision; + $this->assertNotSame($before, $revision->id, 'Eine neue Revision ist gespeichert.'); + $this->assertSame('Direkt aus dem Baustein gespeichert', $revision->sections[0]['slots'][0]['data']['heading']); + $this->assertNotSame($revision->id, $page->fresh()->published_revision_id, 'Speichern veröffentlicht nicht.'); + } + public function test_a_design_error_from_the_page_layout_opens_the_failing_section(): void { $page = Page::query()->where('path', '/')->firstOrFail(); diff --git a/tests/Feature/CmsWebsiteMediaTest.php b/tests/Feature/CmsWebsiteMediaTest.php index 4589b40..2be8a78 100644 --- a/tests/Feature/CmsWebsiteMediaTest.php +++ b/tests/Feature/CmsWebsiteMediaTest.php @@ -221,6 +221,54 @@ public function test_the_picker_lists_website_images_with_their_release_state(): $this->assertStringContainsString(route('editorial.card', ['kind' => 'element', 'subject' => $released->id]), $options[$released->id]); } + public function test_a_block_image_is_chosen_through_the_shared_picker_and_saved_with_the_draft(): void + { + $medium = $this->releasedImage('Lara im Park', 'Lara sitzt auf einer Parkbank'); + $page = Page::query()->firstOrCreate(['path' => '/bild-picker']); + app(PageService::class)->saveRevision($page, [ + ['layout' => 'u4', 'style' => [], 'slots' => [['type' => 'hero', 'v' => 2, 'variant' => 'photo_split', 'data' => ['heading' => 'Einstieg']]]], + ], null, null, null); + $editor = User::factory()->redakteur()->create(); + $editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP'); + + $component = Livewire::actingAs($editor, 'staff')->test(EditPage::class, ['record' => $page->id]); + $sectionKey = array_key_first($component->get('data.sections')); + $slotKey = array_key_first($component->get("data.sections.$sectionKey.slots")); + $widgetKey = array_key_first($component->get("data.sections.$sectionKey.slots.$slotKey.widget")); + $component->mountAction(TestAction::make('edit')->schemaComponent("sections.$sectionKey.slots.$slotKey.widget")->arguments(['item' => $widgetKey])) + ->call('openWebsiteImagePicker', 'mountedActions.0.data.refs.image') + ->assertSet('pickerOpen', true) + ->assertSet('pickerPurpose', 'website-bild') + ->assertSee('Bild aus dem Medienmanager') + ->assertSee('Lara im Park'); + + $target = collect($component->instance()->pickerResult()['items'])->firstWhere('element_id', $medium->id)['target'] ?? null; + $this->assertNotNull($target, 'Das Bild erscheint im gemeinsamen Picker.'); + + $component->call('markPicker', $target, true) + ->call('confirmPicker') + ->assertSet('pickerOpen', false) + ->assertSet('mountedActions.0.data.refs.image', $medium->id) + ->callMountedAction() + ->call('save') + ->assertHasNoErrors(); + + $this->assertSame($medium->id, $page->fresh()->latestRevision->sections[0]['slots'][0]['refs']['image']); + } + + public function test_the_picker_rejects_paths_outside_the_form(): void + { + $page = Page::query()->firstOrCreate(['path' => '/bild-picker-pfad']); + app(PageService::class)->saveRevision($page, [['layout' => 'u4', 'style' => [], 'slots' => [['type' => 'heading', 'v' => 1, 'data' => ['heading' => 'X']]]]], null, null, null); + $editor = User::factory()->redakteur()->create(); + $editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP'); + + Livewire::actingAs($editor, 'staff')->test(EditPage::class, ['record' => $page->id]) + ->call('openWebsiteImagePicker', 'register') + ->assertSet('pickerOpen', false) + ->assertSet('bildZiel', null); + } + private function releasedImage(string $title, ?string $alt): ContentElement { $path = 'cms/'.Str::slug($title).'.jpg';