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>
This commit is contained in:
1 parent
5548106c31
commit
75596bdaec
14 files changed
+520
-188
No files matched your search
@@ -0,0 +1,207 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Support;
|
||||
|
||||
use App\Domain\Catalog\ContentElement;
|
||||
use App\Domain\Catalog\ContentElementVersion;
|
||||
use App\Domain\Cms\Catalog\PublicMaterialReader;
|
||||
use App\Domain\Cms\Widgets\Support\WebsiteImage;
|
||||
use App\Http\Controllers\ContentPreviewController;
|
||||
|
||||
/**
|
||||
* Gemeinsamer visueller Picker (Dokument 14 §9): Zustand, Suche, Treffer, Betrachten, Markieren und Detail. Die
|
||||
* Ansicht ist filament.verwaltung.picker. Die Seite bestimmt Zweck, Titel, Typen, Mehrfachauswahl und was
|
||||
* „Übernehmen“ bewirkt (pickerAllowsMany, pickerKinds, pickerTitle, pickerConfirmLabel, pickerKontext, confirmPicker,
|
||||
* closePicker). Genutzt von der Redaktion (ManagesEditorialSurface) und vom CMS (ChoosesWebsiteImages).
|
||||
*/
|
||||
trait ChoosesMedia
|
||||
{
|
||||
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<string, string> 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<array<string, mixed>>, 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<string, mixed>|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<array{target: string, label: string, current: bool}>
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Support;
|
||||
|
||||
use App\Domain\Catalog\ContentElement;
|
||||
use App\Domain\Cms\Widgets\Support\WebsiteImage;
|
||||
use Filament\Notifications\Notification;
|
||||
|
||||
/**
|
||||
* Bildauswahl im CMS über den gemeinsamen visuellen Picker (Dokument 14 §9) statt einer eigenen Auswahlliste.
|
||||
* Ein Bildfeld (filament.cms.bild-feld) öffnet den Picker mit seinem Formularpfad; „Bild übernehmen“ schreibt die
|
||||
* Kennung des Mediums in genau dieses Feld, auch im geöffneten Bausteindialog. Gespeichert wird weiterhin nur mit dem
|
||||
* Seitenentwurf. Die Auswahl gibt kein Bild für die Website frei.
|
||||
*/
|
||||
trait ChoosesWebsiteImages
|
||||
{
|
||||
use ChoosesMedia;
|
||||
|
||||
/** Formularpfad des Bildfelds, in das die Auswahl übernommen wird. */
|
||||
public ?string $bildZiel = null;
|
||||
|
||||
public function openWebsiteImagePicker(string $pfad): void
|
||||
{
|
||||
if (preg_match('/^(data|mountedActions\.\d+\.data)(\.[A-Za-z0-9_-]+)+$/', $pfad) !== 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->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<string, string>
|
||||
*/
|
||||
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<string, string>
|
||||
*/
|
||||
public function presentationRoleOptions(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>|null
|
||||
*/
|
||||
public function pickerReplacing(): ?array
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
private function forceRenderForPicker(): void
|
||||
{
|
||||
if (method_exists($this, 'forceRender')) {
|
||||
$this->forceRender();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<string, string> 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<array<string, mixed>>, 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<string, mixed>|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<array{target: string, label: string, current: bool}>
|
||||
*/
|
||||
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<string, string>
|
||||
*/
|
||||
@@ -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) {
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user