Make the slide image description optional
CI / Deploy / PHP 8.4 (push) Successful in 1m12s
CI / Deploy / PHP 8.5 (push) Successful in 1m13s
CI / Deploy / test (push) Successful in 1s
CI / Deploy / deploy (push) Skipped

A missing description rejected the whole save and dropped the selected
file, which cannot be refilled in the form. The description is now an
optional hint for screen readers; empty means alt="". The "decorative"
checkbox is gone, it meant the same.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
gnilebeinandClaude Sonnet 5.5 committed 2026-11-15 13:56:27 +01:00
1 parent 8522918c75
commit 33c75e504f
4 files changed
+13 -38

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/`**,
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.
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
(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()`).
+3 -6
View File
@@ -415,15 +415,12 @@ class SlidesController extends AdminAppController
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);
$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;
$slide->patch([
'image_alt' => $decorative ? '' : $alt,
'image_alt' => $alt,
'image_layout' => in_array($layout, Slide::IMAGE_LAYOUTS, true) ? $layout : null,
], ['guard' => false]);
$this->setErrors($slide, $errors);
+4 -18
View File
@@ -20,9 +20,6 @@ $posted = $request->is(['post', 'put', 'patch']);
$hasImage = $slide->hasImage();
// After a failed save the posted values are shown again.
$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)
? (string)$request->getData('image_layout')
: $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)');
}
$imageError = $slide->getError('image');
$altError = $slide->getError('image_alt');
$maxMb = (int)round((int)Configure::read('Plenario.images.maxUploadBytes', 10 * 1024 * 1024) / 1024 / 1024);
?>
<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>
<?php endif; ?>
</div>
<div class="input text<?= $altError ? ' error' : '' ?>">
<label for="image-alt"><?= __('Bildbeschreibung (für Screenreader)') ?></label>
<div class="input text">
<label for="image-alt"><?= __('Bildbeschreibung (optional)') ?></label>
<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')) ?>"
aria-describedby="image-alt-hint<?= $altError ? ' image-alt-error' : '' ?>" <?= $altError ? 'aria-invalid="true"' : '' ?>>
<p class="hint" id="image-alt-hint"><?= __('Pflicht, sobald ein Bild gesetzt ist – oder das Bild ist reine Dekoration.') ?></p>
<?php if ($altError) : ?>
<div class="error-message" id="image-alt-error"><?= h(implode(' ', (array)$altError)) ?></div>
<?php endif; ?>
aria-describedby="image-alt-hint">
<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>
</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">
<legend><?= __('Platzierung in der Präsentation') ?></legend>
<?= $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');
}
public function testImageNeedsAltTextOrDecorativeFlag(): void
public function testImageDescriptionIsOptional(): void
{
[$poll, $token] = $this->createPoll();
$this->postWithImage("/admin/$token/slides/add?type=content", [
'type' => 'content',
'question' => 'Ohne Text',
'question' => 'Ohne Beschreibung',
], $this->makeImage());
$this->assertResponseOk();
$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());
$this->assertRedirect(['_name' => 'admin', 'token' => $token]);
$slide = $this->slidesTable()->find()->where(['poll_id' => $poll->id])->firstOrFail();
$this->assertSame('', $slide->image_alt);
$this->assertTrue($slide->hasImage());
$this->assertSame('', $slide->image_alt);
$this->assertSame([$slide->image], $this->storedImages($poll->id));
}
public function testRejectsFilesThatAreNoImages(): void