Add YouTube video slide type
Admins paste a YouTube link (watch, youtu.be, shorts, live, embed). The link is checked via oEmbed on save and with a "check link" button (not found / not embeddable is rejected, unreachable saves with a warning). Start time can be entered or is taken from the link's timecode; autoplay is optional. The presenter embeds the video via youtube-nocookie.com; participants get the link plus a share button (Web Share API, falls back to copying). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
93aeae1884
commit
1c509e31c2
14 files changed
+972
-24
No files matched your search
@@ -11,6 +11,9 @@
|
||||
* @var list<array{label: string, correct: bool}> $quizOptions
|
||||
* @var bool|null $hasResponses
|
||||
*/
|
||||
|
||||
use App\Service\YouTubeService;
|
||||
|
||||
$isNew = $slide->isNew();
|
||||
$settings = $slide->getSettings();
|
||||
$this->assign('title', $isNew ? __('Neue Folie') : __('Folie bearbeiten'));
|
||||
@@ -28,11 +31,75 @@ $optionsError = $slide->getError('options_text');
|
||||
|
||||
<?= $this->Form->create($slide, ['url' => $formUrl]) ?>
|
||||
<?= $this->Form->hidden('type') ?>
|
||||
<?php if ($slide->isYouTube()) :
|
||||
$urlError = $slide->getError('youtube_url');
|
||||
$startError = $slide->getError('youtube_start');
|
||||
$linkStart = YouTubeService::parseUrl((string)$settings['url'])['start'] ?? null;
|
||||
// Leave the field empty when the start comes from the link, so a changed link wins.
|
||||
$startValue = $this->getRequest()->is(['post', 'put', 'patch'])
|
||||
? (string)$this->getRequest()->getData('settings.start', '')
|
||||
: ((int)$settings['start'] > 0 && (int)$settings['start'] !== $linkStart ? YouTubeService::formatTime((int)$settings['start']) : '');
|
||||
$previewUrl = $settings['video_id'] !== '' && !$urlError
|
||||
? YouTubeService::embedUrl((string)$settings['video_id'], (int)$settings['start'])
|
||||
: null;
|
||||
?>
|
||||
<div class="youtube-fields" data-youtube-form="<?= h($this->Url->build(['_name' => 'slides:youtube-check', 'token' => $adminToken])) ?>">
|
||||
<div class="input text required<?= $urlError ? ' error' : '' ?>">
|
||||
<label for="youtube-url"><?= __('YouTube-Link') ?></label>
|
||||
<div class="copy-field">
|
||||
<input type="text" inputmode="url" id="youtube-url" name="settings[url]" maxlength="500" required
|
||||
autocomplete="off" spellcheck="false" <?= $isNew ? 'autofocus' : '' ?>
|
||||
value="<?= h((string)$settings['url']) ?>"
|
||||
placeholder="https://www.youtube.com/watch?v=dQw4w9WgXcQ"
|
||||
aria-describedby="youtube-url-hint youtube-status<?= $urlError ? ' youtube-url-error' : '' ?>"
|
||||
<?= $urlError ? 'aria-invalid="true"' : '' ?> data-youtube-url>
|
||||
<button type="button" class="button" data-youtube-check hidden><?= __('Link prüfen') ?></button>
|
||||
</div>
|
||||
<p class="hint" id="youtube-url-hint"><?= __('Links von youtube.com, youtu.be und Shorts funktionieren. Beim Speichern wird geprüft, ob das Video existiert und eingebettet werden darf.') ?></p>
|
||||
<?php if ($urlError) : ?>
|
||||
<div class="error-message" id="youtube-url-error"><?= h(implode(' ', (array)$urlError)) ?></div>
|
||||
<?php endif; ?>
|
||||
<p class="youtube-status" id="youtube-status" role="status" aria-live="polite" data-youtube-status></p>
|
||||
</div>
|
||||
<div class="youtube-preview" data-youtube-preview <?= $previewUrl ? '' : 'hidden' ?>>
|
||||
<?php if ($previewUrl) : ?>
|
||||
<iframe src="<?= h($previewUrl) ?>" title="<?= __('Vorschau des Videos') ?>" loading="lazy"
|
||||
referrerpolicy="strict-origin" allow="encrypted-media; picture-in-picture; fullscreen" allowfullscreen></iframe>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<div class="input text<?= $startError ? ' error' : '' ?>">
|
||||
<label for="youtube-start"><?= __('Start bei (Minute:Sekunde, optional)') ?></label>
|
||||
<input type="text" id="youtube-start" name="settings[start]" class="input-short" maxlength="10"
|
||||
inputmode="numeric" autocomplete="off" value="<?= h($startValue) ?>"
|
||||
placeholder="<?= h($linkStart !== null ? YouTubeService::formatTime($linkStart) : '0:00') ?>"
|
||||
aria-describedby="youtube-start-hint<?= $startError ? ' youtube-start-error' : '' ?>"
|
||||
<?= $startError ? 'aria-invalid="true"' : '' ?> data-youtube-start>
|
||||
<p class="hint" id="youtube-start-hint" data-youtube-start-hint><?= $linkStart !== null
|
||||
? __('Leer lassen, um beim Zeitpunkt aus dem Link ({0}) zu starten.', YouTubeService::formatTime($linkStart))
|
||||
: __('Z. B. 1:30 oder nur die Minute (2). Leer lassen, um am Anfang bzw. beim Zeitpunkt aus dem Link (…&t=90s) zu starten.') ?></p>
|
||||
<?php if ($startError) : ?>
|
||||
<div class="error-message" id="youtube-start-error"><?= h(implode(' ', (array)$startError)) ?></div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?= $this->Form->control('settings.autoplay', [
|
||||
'type' => 'checkbox',
|
||||
'label' => __('Automatisch abspielen, sobald die Folie in der Präsentation erscheint'),
|
||||
'checked' => (bool)$settings['autoplay'],
|
||||
]) ?>
|
||||
<p class="hint"><?= __('Manche Browser spielen Videos mit Ton erst automatisch ab, nachdem du in der Präsentation einmal geklickt oder eine Taste gedrückt hast.') ?></p>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?= $this->Form->control('question', [
|
||||
'label' => $slide->type === 'content' ? __('Überschrift') : __('Frage'),
|
||||
'label' => match ($slide->type) {
|
||||
'content' => __('Überschrift'),
|
||||
'youtube' => __('Titel'),
|
||||
default => __('Frage'),
|
||||
},
|
||||
'maxlength' => 500,
|
||||
'required' => true,
|
||||
'autofocus' => $isNew,
|
||||
'required' => !$slide->isYouTube(),
|
||||
'autofocus' => $isNew && !$slide->isYouTube(),
|
||||
'placeholder' => $slide->isYouTube() ? __('Leer lassen, um den Titel des Videos zu übernehmen') : null,
|
||||
'data-youtube-title' => $slide->isYouTube() ? '' : null,
|
||||
]) ?>
|
||||
<?= $this->Form->control('description', [
|
||||
'type' => 'textarea',
|
||||
|
||||
Reference in new issue
Block a user