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,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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user