Erlaube in PDF-Vorlagen jedes Bild des Medienmanagers, auch ohne Inhaltsfassung
Kopf-, Fuß- und Titelbild einer PDF-Vorlage sind Gestaltung und brauchen keine Inhaltsfassung. Der Picker bietet auch Präsentationsmedien und für die Website freigegebene Bilder an (Spalten *_element_id, Klasse TemplateImage); gedruckt wird die Website-Datei, sonst die Präsentationsdatei. Abgelehnt werden nur gesperrte oder archivierte Bilder, fehlende Dateien und Nicht-Bilder. Bilder im Text eines Dokuments bleiben an freigegebene Bildfassungen gebunden. Die öffentliche Eigenschaft heißt bilder, weil slots mit Livewires internem Slot-Mechanismus kollidiert. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
765b8e779e
commit
58b68b768c
13 files changed
+369
-85
No files matched your search
@@ -2,10 +2,8 @@
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use App\Domain\Catalog\ContentElementVersion;
|
||||
use App\Domain\Catalog\ContentVersionStatus;
|
||||
use App\Domain\Catalog\EmbeddedImages;
|
||||
use App\Domain\Catalog\PdfTemplate;
|
||||
use App\Domain\Catalog\TemplateImage;
|
||||
use App\Filament\Resources\ContentElements\ContentElementResource;
|
||||
use App\Filament\Support\ChoosesMedia;
|
||||
use Filament\Notifications\Notification;
|
||||
@@ -46,11 +44,12 @@ class PdfVorlagen extends Page
|
||||
|
||||
public bool $showCover = true;
|
||||
|
||||
public ?int $headerId = null;
|
||||
|
||||
public ?int $footerId = null;
|
||||
|
||||
public ?int $coverId = null;
|
||||
/**
|
||||
* Die Bilder je Bildfeld (header, footer, cover) als Ziel des Pickers: `element:<Fassung>` oder `medium:<Medium>`.
|
||||
*
|
||||
* @var array<string, string|null>
|
||||
*/
|
||||
public array $bilder = ['header' => null, 'footer' => null, 'cover' => null];
|
||||
|
||||
/** Das Bildfeld, in das die Auswahl übernommen wird: header, footer oder cover. */
|
||||
public ?string $bildFeld = null;
|
||||
@@ -108,16 +107,14 @@ public function changed(): bool
|
||||
$template = $this->templateId > 0 ? PdfTemplate::query()->find($this->templateId) : null;
|
||||
|
||||
if (! $template instanceof PdfTemplate) {
|
||||
return $this->name !== '' || $this->publisher !== '' || $this->copyright !== '' || $this->headerId !== null || $this->footerId !== null || $this->coverId !== null;
|
||||
return $this->name !== '' || $this->publisher !== '' || $this->copyright !== '' || array_filter($this->bilder) !== [];
|
||||
}
|
||||
|
||||
return $this->name !== $template->name
|
||||
|| $this->publisher !== (string) $template->publisher
|
||||
|| $this->copyright !== (string) $template->copyright
|
||||
|| $this->showCover !== (bool) $template->show_cover
|
||||
|| $this->headerId !== $template->header_version_id
|
||||
|| $this->footerId !== $template->footer_version_id
|
||||
|| $this->coverId !== $template->cover_version_id;
|
||||
|| $this->bilder !== $this->templateSlots($template);
|
||||
}
|
||||
|
||||
public function save(): void
|
||||
@@ -130,9 +127,11 @@ public function save(): void
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (['header' => $this->headerId, 'footer' => $this->footerId, 'cover' => $this->coverId] as $slot => $id) {
|
||||
if ($id !== null && $this->imageProblem($id) !== null) {
|
||||
Notification::make()->danger()->title('Das Bild für '.$this->slotLabel($slot).' lässt sich nicht verwenden.')->body((string) $this->imageProblem($id))->send();
|
||||
foreach (PdfTemplate::SLOTS as $slot) {
|
||||
$problem = $this->bilder[$slot] === null ? null : TemplateImage::problem($this->bilder[$slot]);
|
||||
|
||||
if ($problem !== null) {
|
||||
Notification::make()->danger()->title('Das Bild für '.$this->slotLabel($slot).' lässt sich nicht verwenden.')->body($problem)->send();
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -142,9 +141,9 @@ public function save(): void
|
||||
'name' => trim($this->name),
|
||||
'kind' => PdfTemplate::KIND_DOCUMENT,
|
||||
'show_cover' => $this->showCover,
|
||||
'header_version_id' => $this->headerId,
|
||||
'footer_version_id' => $this->footerId,
|
||||
'cover_version_id' => $this->coverId,
|
||||
...PdfTemplate::columns('header', $this->bilder['header']),
|
||||
...PdfTemplate::columns('footer', $this->bilder['footer']),
|
||||
...PdfTemplate::columns('cover', $this->bilder['cover']),
|
||||
'publisher' => trim($this->publisher) === '' ? null : trim($this->publisher),
|
||||
'copyright' => trim($this->copyright) === '' ? null : trim($this->copyright),
|
||||
];
|
||||
@@ -202,12 +201,9 @@ public function openImagePicker(string $slot): void
|
||||
|
||||
public function clearImage(string $slot): void
|
||||
{
|
||||
match ($slot) {
|
||||
'header' => $this->headerId = null,
|
||||
'footer' => $this->footerId = null,
|
||||
'cover' => $this->coverId = null,
|
||||
default => null,
|
||||
};
|
||||
if (in_array($slot, PdfTemplate::SLOTS, true)) {
|
||||
$this->bilder[$slot] = null;
|
||||
}
|
||||
}
|
||||
|
||||
public function pickerAllowsMany(): bool
|
||||
@@ -229,11 +225,11 @@ public function confirmPicker(): void
|
||||
$target = array_key_first($this->pickerMarked);
|
||||
$slot = $this->bildFeld;
|
||||
|
||||
if ($target === null || $slot === null || preg_match('/^element:(\d+)$/', (string) $target, $match) !== 1) {
|
||||
if ($target === null || $slot === null || ! in_array($slot, PdfTemplate::SLOTS, true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$problem = $this->imageProblem((int) $match[1]);
|
||||
$problem = TemplateImage::problem((string) $target);
|
||||
|
||||
if ($problem !== null) {
|
||||
Notification::make()->danger()->title('Dieses Bild lässt sich nicht verwenden.')->body($problem)->send();
|
||||
@@ -241,12 +237,7 @@ public function confirmPicker(): void
|
||||
return;
|
||||
}
|
||||
|
||||
match ($slot) {
|
||||
'header' => $this->headerId = (int) $match[1],
|
||||
'footer' => $this->footerId = (int) $match[1],
|
||||
'cover' => $this->coverId = (int) $match[1],
|
||||
default => null,
|
||||
};
|
||||
$this->bilder[$slot] = (string) $target;
|
||||
$this->closePicker();
|
||||
}
|
||||
|
||||
@@ -284,16 +275,14 @@ public function pickerReplacing(): ?array
|
||||
return null;
|
||||
}
|
||||
|
||||
public function imageUrl(?int $versionId): ?string
|
||||
public function imageUrl(?string $target): ?string
|
||||
{
|
||||
return $versionId === null ? null : EmbeddedImages::staffSource($versionId);
|
||||
return TemplateImage::previewUrl($target);
|
||||
}
|
||||
|
||||
public function imageTitle(?int $versionId): string
|
||||
public function imageTitle(?string $target): string
|
||||
{
|
||||
$version = $versionId === null ? null : ContentElementVersion::query()->with('element')->find($versionId);
|
||||
|
||||
return $version?->element === null ? '' : (string) ($version->element->display_title ?: $version->element->working_title);
|
||||
return TemplateImage::title($target);
|
||||
}
|
||||
|
||||
public function slotLabel(string $slot): string
|
||||
@@ -306,21 +295,6 @@ public function slotLabel(string $slot): string
|
||||
};
|
||||
}
|
||||
|
||||
private function imageProblem(int $versionId): ?string
|
||||
{
|
||||
$version = ContentElementVersion::query()->with('element')->find($versionId);
|
||||
|
||||
if (! $version instanceof ContentElementVersion || $version->element === null || $version->element->output_class !== 'bild') {
|
||||
return 'Das ist kein Bild des Medienbestands.';
|
||||
}
|
||||
|
||||
if ($version->status !== ContentVersionStatus::Bereit) {
|
||||
return 'Die Bildfassung ist noch nicht freigegeben.';
|
||||
}
|
||||
|
||||
return EmbeddedImages::file($version) === null ? 'Die Bilddatei liegt nicht vor.' : null;
|
||||
}
|
||||
|
||||
private function loadTemplate(PdfTemplate $template): void
|
||||
{
|
||||
$this->templateId = $template->id;
|
||||
@@ -328,9 +302,15 @@ private function loadTemplate(PdfTemplate $template): void
|
||||
$this->publisher = (string) $template->publisher;
|
||||
$this->copyright = (string) $template->copyright;
|
||||
$this->showCover = (bool) $template->show_cover;
|
||||
$this->headerId = $template->header_version_id;
|
||||
$this->footerId = $template->footer_version_id;
|
||||
$this->coverId = $template->cover_version_id;
|
||||
$this->bilder = $this->templateSlots($template);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string|null>
|
||||
*/
|
||||
private function templateSlots(PdfTemplate $template): array
|
||||
{
|
||||
return ['header' => $template->target('header'), 'footer' => $template->target('footer'), 'cover' => $template->target('cover')];
|
||||
}
|
||||
|
||||
private function clearForm(): void
|
||||
@@ -340,9 +320,7 @@ private function clearForm(): void
|
||||
$this->publisher = '';
|
||||
$this->copyright = '';
|
||||
$this->showCover = true;
|
||||
$this->headerId = null;
|
||||
$this->footerId = null;
|
||||
$this->coverId = null;
|
||||
$this->bilder = ['header' => null, 'footer' => null, 'cover' => null];
|
||||
}
|
||||
|
||||
protected function pickerExceptId(): int
|
||||
|
||||
@@ -106,8 +106,13 @@ public function pickerResult(): array
|
||||
return ['items' => [], 'more' => false];
|
||||
}
|
||||
|
||||
if (in_array($this->pickerPurpose, ['aufbau', 'textbild', 'vorlagenbild'], true)) {
|
||||
$image = in_array($this->pickerPurpose, ['textbild', 'vorlagenbild'], true);
|
||||
// Eine PDF-Vorlage nimmt auch Bilder ohne Inhaltsfassung (Präsentationsmedien, Website-Bilder) auf.
|
||||
if ($this->pickerPurpose === 'vorlagenbild') {
|
||||
return $this->filterByMaterialart(app(EditorialCatalog::class)->presentationBrowse($this->pickerQuery, 'bild'));
|
||||
}
|
||||
|
||||
if (in_array($this->pickerPurpose, ['aufbau', 'textbild'], true)) {
|
||||
$image = $this->pickerPurpose === 'textbild';
|
||||
|
||||
return $this->filterByMaterialart(app(EditorialCatalog::class)->browse(
|
||||
$this->pickerQuery,
|
||||
|
||||
Reference in new issue
Block a user