Redesign the image section of the slide form

Show a dropzone (with drag and drop) while a slide has no image and a
row with preview, replace and remove buttons otherwise. A newly chosen
file is previewed right away. Placement is picked from tiles with a
small sketch instead of long radio labels, technical details move into
a collapsible help. The section gets full-width dividers, and the modal
a slim scrollbar.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
gnilebeinandClaude Sonnet 5.5 committed 2026-11-17 14:21:27 +01:00
1 parent 0ad29aa484
commit c6a92e347f
5 files changed
+257 -92

No files matched your search

+83 -45
View File
@@ -1,7 +1,8 @@
<?php
/**
* Image fields of the slide form: upload, alternative text, layout, remove.
* Not for slide types without image support (YouTube).
* Image section of the slide form: dropzone or current image (replace / remove), placement tiles.
* Works without JavaScript (label opens the file dialog, checkbox removes); JavaScript adds
* preview, drag and drop and the remove toggle. Not for slide types without image support (YouTube).
*
* @var \App\View\AppView $this
* @var \App\Model\Entity\Slide $slide
@@ -23,62 +24,99 @@ $layout = $posted && in_array($request->getData('image_layout'), Slide::IMAGE_LA
? (string)$request->getData('image_layout')
: $slide->imageLayout();
$layouts = [
Slide::IMAGE_TOP => __('Oben (über den Antworten bzw. Ergebnissen)'),
Slide::IMAGE_SIDE => __('Daneben (Bild links, Text und Ergebnis rechts)'),
Slide::IMAGE_TOP => [__('Oben'), '<rect class="img" x="4" y="3" width="40" height="13" rx="2"/><rect x="4" y="20" width="30" height="3" rx="1.5"/><rect x="4" y="26" width="22" height="3" rx="1.5"/>'],
Slide::IMAGE_SIDE => [__('Daneben'), '<rect class="img" x="4" y="3" width="18" height="26" rx="2"/><rect x="27" y="6" width="17" height="3" rx="1.5"/><rect x="27" y="12" width="13" height="3" rx="1.5"/><rect x="27" y="18" width="17" height="3" rx="1.5"/>'],
];
if ($slide->type === Slide::TYPE_CONTENT) {
$layouts[Slide::IMAGE_FULL] = __('Bildschirm füllen (Bild so groß wie möglich)');
$layouts[Slide::IMAGE_FULL] = [__('Vollbild'), '<rect class="img" x="4" y="3" width="40" height="26" rx="2"/>'];
}
$imageError = $slide->getError('image');
$maxMb = (int)round((int)Configure::read('Plenario.images.maxUploadBytes', 10 * 1024 * 1024) / 1024 / 1024);
$imageUrl = $hasImage
? $this->Url->build(['_name' => 'participate:image', 'code' => $poll->join_code, 'file' => $slide->image])
: '';
?>
<fieldset class="image-fields" data-image-fields<?= $hasImage ? ' data-has-image' : '' ?>>
<legend><?= __('Bild (optional)') ?></legend>
<div class="image-section" data-image-fields<?= $hasImage ? ' data-has-image' : '' ?>>
<fieldset class="image-fields">
<legend><?= __('Bild') ?> <span class="image-fields__optional"><?= __('(optional)') ?></span></legend>
<?php if (!ImageService::isAvailable()) : ?>
<p class="hint"><?= __('Bilder sind auf diesem Server nicht verfügbar (PHP-Erweiterung GD mit WebP fehlt).') ?></p>
<?php else : ?>
<?php if ($hasImage) : ?>
<figure class="image-fields__current">
<img src="<?= h($this->Url->build(['_name' => 'participate:image', 'code' => $poll->join_code, 'file' => $slide->image])) ?>"
alt="<?= h((string)$slide->image_alt) ?>" width="<?= (int)$slide->image_width ?>" height="<?= (int)$slide->image_height ?>">
</figure>
<?php // Without JavaScript the checkbox does the job; with it, the button toggles the same checkbox. ?>
<div class="image-fields__remove" data-image-remove>
<?= $this->Form->control('remove_image', [
'type' => 'checkbox',
'label' => __('Bild entfernen'),
'value' => '1',
'hiddenField' => false,
'checked' => false,
]) ?>
<button type="button" class="button button--danger button--small" hidden aria-pressed="false" data-image-remove-button
data-label-remove="<?= h(__('Bild entfernen')) ?>" data-label-undo="<?= h(__('Entfernen rückgängig machen')) ?>">
<svg width="1em" height="1em" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<path d="M3 6h18M8 6V4h8v2M6 6l1 14h10l1-14M10 11v5M14 11v5"/>
</svg>
<span data-label><?= __('Bild entfernen') ?></span>
</button>
<span class="hint" role="status" aria-live="polite" data-image-remove-status></span>
</div>
<?php if ($imageError) : ?>
<div class="error-message" id="image-error" role="alert"><?= h(implode(' ', (array)$imageError)) ?></div>
<?php endif; ?>
<div class="input file<?= $imageError ? ' error' : '' ?>">
<label for="image-file"><?= $hasImage ? __('Anderes Bild hochladen') : __('Bild hochladen') ?></label>
<input type="file" id="image-file" name="image" accept="image/jpeg,image/png,image/webp,image/gif"
aria-describedby="image-hint<?= $imageError ? ' image-error' : '' ?>" <?= $imageError ? 'aria-invalid="true"' : '' ?>>
<p class="hint" id="image-hint"><?= __('JPEG, PNG, WebP oder GIF (nicht animiert), bis {0} MB. Das Bild wird automatisch auf höchstens 1600 Pixel verkleinert und als WebP gespeichert, Kameradaten wie der Aufnahmeort werden dabei entfernt.', $maxMb) ?></p>
<?php if ($imageError) : ?>
<div class="error-message" id="image-error"><?= h(implode(' ', (array)$imageError)) ?></div>
<?php endif; ?>
<?php // One file input for both states; the labels below open it, so it can stay visually hidden. ?>
<input type="file" id="image-file" name="image" class="sr-only" accept="image/jpeg,image/png,image/webp,image/gif"
aria-describedby="image-hint<?= $imageError ? ' image-error' : '' ?>" <?= $imageError ? 'aria-invalid="true"' : '' ?>>
<label class="image-drop" for="image-file" data-image-drop<?= $hasImage ? ' hidden' : '' ?>>
<svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6"
stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<rect x="3" y="4" width="18" height="16" rx="2"/><circle cx="9" cy="10" r="1.5"/><path d="M21 16l-5-5-8 9"/>
</svg>
<span class="image-drop__title"><?= __('Bild auswählen') ?><span data-image-drop-extra hidden> <?= __('oder hierher ziehen') ?></span></span>
<span class="image-drop__hint"><?= __('JPEG, PNG, WebP oder GIF, bis {0} MB', $maxMb) ?></span>
</label>
<div class="image-fields__row" data-image-row<?= $hasImage ? '' : ' hidden' ?>>
<figure class="image-fields__current" data-image-figure>
<img src="<?= h($imageUrl) ?>" alt="" data-image-original="<?= h($imageUrl) ?>"
<?= $hasImage ? 'width="' . (int)$slide->image_width . '" height="' . (int)$slide->image_height . '"' : '' ?>>
</figure>
<div class="image-fields__side">
<p class="image-fields__info" role="status" aria-live="polite" data-image-info
data-text-current="<?= h(__('Aktuelles Bild')) ?><?= $hasImage ? h(' · ' . __('{0} × {1} Pixel', (int)$slide->image_width, (int)$slide->image_height)) : '' ?>"
data-text-new="<?= h(__('Neues Bild wird beim Speichern übernommen:')) ?>"
data-text-removed="<?= h(__('Das Bild wird beim Speichern entfernt.')) ?>"><?= $hasImage ? h(__('Aktuelles Bild') . ' · ' . __('{0} × {1} Pixel', (int)$slide->image_width, (int)$slide->image_height)) : '' ?></p>
<div class="image-fields__buttons">
<label class="button button--small" for="image-file" data-image-pick
data-label-replace="<?= h(__('Ersetzen')) ?>" data-label-choose="<?= h(__('Anderes Bild wählen')) ?>"><?= __('Ersetzen') ?></label>
<?php if ($hasImage) : ?>
<?php // Without JavaScript the checkbox does the job; with it, the button toggles the same checkbox. ?>
<div class="image-fields__remove" data-image-remove>
<?= $this->Form->control('remove_image', [
'type' => 'checkbox',
'label' => __('Bild entfernen'),
'value' => '1',
'hiddenField' => false,
'checked' => false,
]) ?>
</div>
<?php endif; ?>
<button type="button" class="button button--danger button--small" hidden data-image-remove-button
data-label-remove="<?= h(__('Entfernen')) ?>" data-label-undo="<?= h(__('Rückgängig')) ?>"
data-label-discard="<?= h(__('Auswahl verwerfen')) ?>">
<svg width="1em" height="1em" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<path d="M3 6h18M8 6V4h8v2M6 6l1 14h10l1-14M10 11v5M14 11v5"/>
</svg>
<span data-label><?= __('Entfernen') ?></span>
</button>
</div>
</div>
</div>
<fieldset class="scale-style image-fields__layout" data-image-layout>
<div class="image-fields__help" id="image-hint">
<details>
<summary><?= __('Was passiert mit dem Bild?') ?></summary>
<p class="hint"><?= __('JPEG, PNG, WebP oder GIF (nicht animiert), bis {0} MB. Das Bild wird automatisch auf höchstens 1600 Pixel verkleinert und als WebP gespeichert, Kameradaten wie der Aufnahmeort werden dabei entfernt.', $maxMb) ?></p>
</details>
</div>
<fieldset class="image-layout" data-image-layout>
<legend><?= __('Platzierung in der Präsentation') ?></legend>
<?= $this->Form->radio('image_layout', array_map(
fn($value, $text) => ['value' => $value, 'text' => $text],
array_keys($layouts),
$layouts,
), ['value' => $layout]) ?>
<div class="image-layout__tiles">
<?php foreach ($layouts as $value => [$text, $shapes]) : ?>
<label class="image-layout__tile">
<input type="radio" name="image_layout" value="<?= h($value) ?>" class="sr-only" <?= $layout === $value ? 'checked' : '' ?>>
<svg viewBox="0 0 48 32" width="72" height="48" fill="currentColor" aria-hidden="true"><?= $shapes ?></svg>
<span><?= h($text) ?></span>
</label>
<?php endforeach; ?>
</div>
<p class="hint"><?= __('Auf dem Smartphone der Teilnehmenden steht das Bild immer oben.') ?></p>
</fieldset>
<?php endif; ?>
</fieldset>
</div>