Feature/slide images #81

Merged
gnilebein merged 3 commits from feature/slide-images into main 2026-11-15 14:02:41 +01:00
4 changed files with 13 additions and 38 deletions
Showing only changes of commit 33c75e504f - Show all commits

No files matched your search

+1 -1
View File
@@ -215,7 +215,7 @@ tests/ PHPUnit; PlenarioTestTrait erzeugt Testdaten, Fixtures
Ablage `{Plenario.images.path}/{poll_id}/{24 Hex}.webp` (Standard `data/uploads`, Docker `/data/uploads`) **außerhalb von `webroot/`**, Ablage `{Plenario.images.path}/{poll_id}/{24 Hex}.webp` (Standard `data/uploads`, Docker `/data/uploads`) **außerhalb von `webroot/`**,
ausgeliefert über `participate:image` (`/p/{code}/img/{file}`, auch für Presenter und Einbettung; nur Dateien dieser Umfrage, `immutable` ausgeliefert über `participate:image` (`/p/{code}/img/{file}`, auch für Presenter und Einbettung; nur Dateien dieser Umfrage, `immutable`
gecacht, kein Cookie). Jedes neue Bild bekommt einen neuen Namen → neue URL, ersetzte Bilder sind sofort 404. gecacht, kein Cookie). Jedes neue Bild bekommt einen neuen Namen → neue URL, ersetzte Bilder sind sofort 404.
Alt-Text ist Pflicht (`image_alt`), außer „Reine Dekoration“ (`image_alt = ''`). Layout `image_layout` (`top`|`side`|`full`, `full` nur Die Bildbeschreibung (`image_alt`) ist optional (leer = `alt=""`) und darf nie zur Ablehnung führen: das Dateifeld lässt sich nach einem Fehler nicht neu füllen. Layout `image_layout` (`top`|`side`|`full`, `full` nur
Inhaltsfolien, `null` = Standard je Typ: Inhaltsfolie `side`, sonst `top`; `Slide::imageLayout()`); `side` gilt nur für die Bühne Inhaltsfolien, `null` = Standard je Typ: Inhaltsfolie `side`, sonst `top`; `Slide::imageLayout()`); `side` gilt nur für die Bühne
(CSS `stage--img-*`), Teilnehmende sehen das Bild immer oben (`element/slide_image`). Kontingent `Plenario.images.maxPerPoll` Folien mit Bild. (CSS `stage--img-*`), Teilnehmende sehen das Bild immer oben (`element/slide_image`). Kontingent `Plenario.images.maxPerPoll` Folien mit Bild.
Im State steht `slide.image` = `{url, alt, layout, width, height}` (`PollStateService::slidePayload()`). Im State steht `slide.image` = `{url, alt, layout, width, height}` (`PollStateService::slidePayload()`).
+3 -6
View File
@@ -415,15 +415,12 @@ class SlidesController extends AdminAppController
return $state; return $state;
} }
// Without an image to describe, accessibility needs either a text or the explicit "decorative". // The description is optional (recommended for screen readers); empty means alt="" (skipped by them).
// Never reject an upload for it: the file input cannot be refilled after a failed save.
$alt = mb_substr(trim((string)($data['image_alt'] ?? '')), 0, Slide::IMAGE_ALT_MAX); $alt = mb_substr(trim((string)($data['image_alt'] ?? '')), 0, Slide::IMAGE_ALT_MAX);
$decorative = filter_var($data['image_decorative'] ?? false, FILTER_VALIDATE_BOOLEAN);
if (!$decorative && $alt === '') {
$errors['image_alt'] = __('Bitte beschreibe das Bild kurz (für Menschen mit Screenreader) oder markiere es als reine Dekoration.');
}
$layout = $data['image_layout'] ?? null; $layout = $data['image_layout'] ?? null;
$slide->patch([ $slide->patch([
'image_alt' => $decorative ? '' : $alt, 'image_alt' => $alt,
'image_layout' => in_array($layout, Slide::IMAGE_LAYOUTS, true) ? $layout : null, 'image_layout' => in_array($layout, Slide::IMAGE_LAYOUTS, true) ? $layout : null,
], ['guard' => false]); ], ['guard' => false]);
$this->setErrors($slide, $errors); $this->setErrors($slide, $errors);
+4 -18
View File
@@ -20,9 +20,6 @@ $posted = $request->is(['post', 'put', 'patch']);
$hasImage = $slide->hasImage(); $hasImage = $slide->hasImage();
// After a failed save the posted values are shown again. // After a failed save the posted values are shown again.
$alt = $posted ? (string)$request->getData('image_alt', '') : (string)$slide->image_alt; $alt = $posted ? (string)$request->getData('image_alt', '') : (string)$slide->image_alt;
$decorative = $posted
? filter_var($request->getData('image_decorative'), FILTER_VALIDATE_BOOLEAN)
: ($hasImage && $slide->image_alt === '');
$layout = $posted && in_array($request->getData('image_layout'), Slide::IMAGE_LAYOUTS, true) $layout = $posted && in_array($request->getData('image_layout'), Slide::IMAGE_LAYOUTS, true)
? (string)$request->getData('image_layout') ? (string)$request->getData('image_layout')
: $slide->imageLayout(); : $slide->imageLayout();
@@ -34,7 +31,6 @@ if ($slide->type === Slide::TYPE_CONTENT) {
$layouts[Slide::IMAGE_FULL] = __('Bildschirm füllen (Bild so groß wie möglich)'); $layouts[Slide::IMAGE_FULL] = __('Bildschirm füllen (Bild so groß wie möglich)');
} }
$imageError = $slide->getError('image'); $imageError = $slide->getError('image');
$altError = $slide->getError('image_alt');
$maxMb = (int)round((int)Configure::read('Plenario.images.maxUploadBytes', 10 * 1024 * 1024) / 1024 / 1024); $maxMb = (int)round((int)Configure::read('Plenario.images.maxUploadBytes', 10 * 1024 * 1024) / 1024 / 1024);
?> ?>
<fieldset class="image-fields" data-image-fields> <fieldset class="image-fields" data-image-fields>
@@ -76,23 +72,13 @@ $maxMb = (int)round((int)Configure::read('Plenario.images.maxUploadBytes', 10 *
<div class="error-message" id="image-error"><?= h(implode(' ', (array)$imageError)) ?></div> <div class="error-message" id="image-error"><?= h(implode(' ', (array)$imageError)) ?></div>
<?php endif; ?> <?php endif; ?>
</div> </div>
<div class="input text<?= $altError ? ' error' : '' ?>"> <div class="input text">
<label for="image-alt"><?= __('Bildbeschreibung (für Screenreader)') ?></label> <label for="image-alt"><?= __('Bildbeschreibung (optional)') ?></label>
<input type="text" id="image-alt" name="image_alt" maxlength="<?= Slide::IMAGE_ALT_MAX ?>" autocomplete="off" <input type="text" id="image-alt" name="image_alt" maxlength="<?= Slide::IMAGE_ALT_MAX ?>" autocomplete="off"
value="<?= h($alt) ?>" placeholder="<?= h(__('z. B. Organigramm des Vereins')) ?>" value="<?= h($alt) ?>" placeholder="<?= h(__('z. B. Organigramm des Vereins')) ?>"
aria-describedby="image-alt-hint<?= $altError ? ' image-alt-error' : '' ?>" <?= $altError ? 'aria-invalid="true"' : '' ?>> aria-describedby="image-alt-hint">
<p class="hint" id="image-alt-hint"><?= __('Pflicht, sobald ein Bild gesetzt ist – oder das Bild ist reine Dekoration.') ?></p> <p class="hint" id="image-alt-hint"><?= __('Kurz beschreiben, was zu sehen ist. Das hilft Menschen, die einen Screenreader nutzen. Leer lassen, wenn das Bild nur Dekoration ist.') ?></p>
<?php if ($altError) : ?>
<div class="error-message" id="image-alt-error"><?= h(implode(' ', (array)$altError)) ?></div>
<?php endif; ?>
</div> </div>
<?= $this->Form->control('image_decorative', [
'type' => 'checkbox',
'label' => __('Reine Dekoration (keine Beschreibung nötig)'),
'value' => '1',
'hiddenField' => false,
'checked' => $decorative,
]) ?>
<fieldset class="scale-style image-fields__layout"> <fieldset class="scale-style image-fields__layout">
<legend><?= __('Platzierung in der Präsentation') ?></legend> <legend><?= __('Platzierung in der Präsentation') ?></legend>
<?= $this->Form->radio('image_layout', array_map( <?= $this->Form->radio('image_layout', array_map(
+5 -13
View File
@@ -77,27 +77,19 @@ class SlideImageTest extends TestCase
$this->assertSame(Slide::IMAGE_TOP, $choice->imageLayout(), 'full exists for content slides only'); $this->assertSame(Slide::IMAGE_TOP, $choice->imageLayout(), 'full exists for content slides only');
} }
public function testImageNeedsAltTextOrDecorativeFlag(): void public function testImageDescriptionIsOptional(): void
{ {
[$poll, $token] = $this->createPoll(); [$poll, $token] = $this->createPoll();
$this->postWithImage("/admin/$token/slides/add?type=content", [ $this->postWithImage("/admin/$token/slides/add?type=content", [
'type' => 'content', 'type' => 'content',
'question' => 'Ohne Text', 'question' => 'Ohne Beschreibung',
], $this->makeImage()); ], $this->makeImage());
$this->assertResponseOk(); $this->assertRedirect(['_name' => 'admin', 'token' => $token]);
$this->assertResponseContains('Bitte beschreibe das Bild');
$this->assertSame(0, $this->slidesTable()->find()->where(['poll_id' => $poll->id])->count());
$this->assertSame([], $this->storedImages($poll->id), 'no file left behind');
$this->postWithImage("/admin/$token/slides/add?type=content", [
'type' => 'content',
'question' => 'Dekoration',
'image_decorative' => '1',
], $this->makeImage());
$slide = $this->slidesTable()->find()->where(['poll_id' => $poll->id])->firstOrFail(); $slide = $this->slidesTable()->find()->where(['poll_id' => $poll->id])->firstOrFail();
$this->assertSame('', $slide->image_alt);
$this->assertTrue($slide->hasImage()); $this->assertTrue($slide->hasImage());
$this->assertSame('', $slide->image_alt);
$this->assertSame([$slide->image], $this->storedImages($poll->id));
} }
public function testRejectsFilesThatAreNoImages(): void public function testRejectsFilesThatAreNoImages(): void