Erlaube in PDF-Vorlagen jedes Bild des Medienmanagers, auch ohne Inhaltsfassung
Deploy Test / test (push) Successful in 3m18s
Deploy Test / deploy (push) Successful in 29s

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:
LarsandClaude Sonnet 5.5 committed 2026-11-24 16:05:09 +01:00
1 parent 765b8e779e
commit 58b68b768c
13 files changed
+369 -85

No files matched your search

+84 -4
View File
@@ -5,6 +5,7 @@
use App\Domain\Catalog\ArticleRelease;
use App\Domain\Catalog\CompositionKind;
use App\Domain\Catalog\CompositionVersion;
use App\Domain\Catalog\ContentElement;
use App\Domain\Catalog\ContentElementVersion;
use App\Domain\Catalog\ContentService;
use App\Domain\Catalog\DocumentMeta;
@@ -35,6 +36,7 @@ protected function setUp(): void
parent::setUp();
Storage::fake('media_derived');
Storage::fake('media_public');
Filament::setCurrentPanel(Filament::getPanel('verwaltung'));
}
@@ -154,7 +156,7 @@ public function test_the_editor_saves_the_details_in_the_draft_and_binds_them_wi
public function test_the_template_page_creates_changes_and_deletes_templates_with_images_from_the_picker(): void
{
$header = $this->picture('Kopf', 2480, 300, [20, 80, 60]);
$draftImage = app(ContentService::class)->draftElementVersion(app(ContentService::class)->createElement('bild', 'bild', 'Entwurf'), null, ['file' => 'inhalte/entwurf.png']);
$draftImage = app(ContentService::class)->draftElementVersion(app(ContentService::class)->createElement('bild', 'bild', 'Entwurf'), null, ['file' => $this->store('inhalte/entwurf.png', 1200, 200, [90, 40, 40])]);
$component = Livewire::actingAs($this->editor(), 'staff')->test(PdfVorlagen::class)->assertOk();
$this->assertSame([], $component->instance()->templates());
@@ -164,9 +166,9 @@ public function test_the_template_page_creates_changes_and_deletes_templates_wit
$this->assertSame(['bild' => 'Bilder'], $component->instance()->pickerKinds());
$this->assertContains('Kopf', array_column($component->instance()->pickerResult()['items'], 'title'));
// Eine nicht freigegebene Fassung wird abgelehnt.
$component->call('markPicker', 'element:'.$draftImage->id, true)->call('confirmPicker')->assertSet('headerId', null);
$component->call('markPicker', 'element:'.$header->id, true)->call('confirmPicker')->assertSet('headerId', $header->id)->assertSet('pickerOpen', false);
// Gestaltung braucht keine freigegebene Fassung: auch ein Bild im Entwurf lässt sich wählen.
$component->call('markPicker', 'element:'.$draftImage->id, true)->call('confirmPicker')->assertSet('bilder.header', 'element:'.$draftImage->id);
$component->call('openImagePicker', 'header')->call('markPicker', 'element:'.$header->id, true)->call('confirmPicker')->assertSet('bilder.header', 'element:'.$header->id)->assertSet('pickerOpen', false);
$this->assertTrue($component->instance()->changed());
$component->call('save');
@@ -184,6 +186,49 @@ public function test_the_template_page_creates_changes_and_deletes_templates_wit
$this->assertSame(0, PdfTemplate::query()->count());
}
public function test_images_without_a_content_version_work_too_presentation_media_and_images_released_for_the_website(): void
{
$presentation = $this->mediumWithoutVersion('Präsentationsbild', [200, 60, 60], released: false);
$web = $this->mediumWithoutVersion('Website-Bild', [60, 60, 200], released: true);
$component = Livewire::actingAs($this->editor(), 'staff')->test(PdfVorlagen::class)->set('name', 'Ohne Fassungen')->call('openImagePicker', 'header');
$titles = array_column($component->instance()->pickerResult()['items'], 'title');
$this->assertContains('Präsentationsbild', $titles, 'Der Picker bietet Bilder ohne Inhaltsfassung an.');
$this->assertContains('Website-Bild', $titles);
$component->call('markPicker', 'medium:'.$presentation->id, true)->call('confirmPicker')->assertSet('bilder.header', 'medium:'.$presentation->id);
$component->call('openImagePicker', 'footer')->call('markPicker', 'medium:'.$web->id, true)->call('confirmPicker')->assertSet('bilder.footer', 'medium:'.$web->id);
$component->call('save');
$template = PdfTemplate::query()->firstOrFail();
$this->assertSame([null, $presentation->id, null, $web->id], [$template->header_version_id, $template->header_element_id, $template->footer_version_id, $template->footer_element_id]);
$this->assertSame(['medium:'.$presentation->id, 'medium:'.$web->id], [$template->target('header'), $template->target('footer')]);
// Beide Bilder stehen im PDF.
[$article, $release, $member] = $this->sold($template, null);
$pdf = $this->actingAs($member)->get(route('member.document.pdf', ['article' => $article, 'release' => $release, 'path' => '1']))->getContent();
$this->assertSame(2, substr_count($pdf, '/Subtype /Image'));
$this->assertNotNull($component->instance()->imageUrl('medium:'.$presentation->id));
$this->assertNotNull($component->instance()->imageUrl('medium:'.$web->id));
}
public function test_a_blocked_image_a_missing_file_and_something_that_is_no_image_are_refused(): void
{
$blocked = $this->picture('Gesperrt', 800, 200);
app(ContentService::class)->block($blocked, 'Rechte');
$noFile = $this->mediumWithoutVersion('Ohne Datei', [1, 1, 1], released: false, file: false);
$film = $this->film('Ein Film');
$component = Livewire::actingAs($this->editor(), 'staff')->test(PdfVorlagen::class)->call('openImagePicker', 'cover');
foreach (['element:'.$blocked->id, 'medium:'.$noFile->id, 'element:'.$film->id] as $target) {
$component->call('markPicker', $target, true)->call('confirmPicker')->assertSet('bilder.cover', null);
$component->call('openImagePicker', 'cover');
}
}
public function test_deleting_a_template_returns_its_documents_to_the_simple_layout(): void
{
$template = $this->template();
@@ -208,6 +253,41 @@ public function test_the_staff_preview_of_a_document_uses_its_template_and_the_d
$this->assertStringContainsString('Entwurfsausgabe 7', $this->pdfPages($pdf)[0]);
}
/** Legt eine Bilddatei im abgeleiteten Bestand ab und liefert ihren Pfad. */
private function store(string $path, int $width, int $height, array $rgb): string
{
$image = imagecreatetruecolor($width, $height);
imagefill($image, 0, 0, (int) imagecolorallocate($image, ...$rgb));
ob_start();
imagepng($image);
Storage::disk('media_derived')->put($path, (string) ob_get_clean());
return $path;
}
/**
* Ein Bild ohne Inhaltsfassung: ein Präsentationsmedium (Datei unter `vorschau/`) oder ein für die Website freigegebenes Bild.
*/
private function mediumWithoutVersion(string $title, array $rgb, bool $released, bool $file = true): ContentElement
{
$element = app(ContentService::class)->createElement('bild', 'bild', $title);
if ($file) {
$path = $this->store('vorschau/'.$element->id.'/datei.png', 2480, 240, $rgb);
$element->thumbnail_path = $path;
if ($released) {
Storage::disk('media_public')->put('website/'.$element->id.'/datei.png', (string) Storage::disk('media_derived')->get($path));
$element->website_public_path = 'website/'.$element->id.'/datei.png';
$element->website_released_at = now();
}
}
$element->save();
return $element;
}
/**
* Eine Vorlage mit Kopf-, Fuß- und Titelbild (drei verschiedene Grafiken).
*/