#6 - Output elements

This commit was merged in pull request #11.
This commit is contained in:
Martin Slachta
2026-06-14 11:07:14 +02:00
parent 3225ff1e10
commit 0fc0addf47
4 changed files with 220 additions and 1 deletions
@@ -0,0 +1,21 @@
<?php
class RsvOutputTextElementHandler implements RsvFormElementHandler {
private const ALLOWED_TAGS = ['p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'];
public function draw(RsvFormElementDefinition $def): void {
$raw = $def->getAttr('tag', 'p');
$tag = in_array($raw, self::ALLOWED_TAGS, true) ? $raw : 'p';
echo '<' . $tag . ' class="rsv-form-output-text">' . esc_html($def->getLabel()) . '</' . $tag . '>';
}
public function submit(RsvFormElementDefinition $def, int $submit_id, array $data, RsvFormSubmitResult $result): bool {
return true;
}
public function rollback(RsvFormElementDefinition $def, int $submit_id, array $data, RsvFormSubmitResult $result): void {
// No side effects to undo.
}
}
+17 -1
View File
@@ -176,7 +176,7 @@ class RsvFormsPage extends RsvAdminPage {
if (idx === -1) return Promise.reject(new Error('Element not found'));
// Destructure reservation-specific fields so they don't bleed into extra_attrs.
const { id: _id, name: _n, label: _l, type: _t, desc: _d, required: _r,
price_per_block: _p, email_templates: _et, timetable_id: _ti, ...extra_attrs } = items[idx];
price_per_block: _p, email_templates: _et, timetable_id: _ti, tag: _tag, ...extra_attrs } = items[idx];
items[idx] = {
...extra_attrs,
id,
@@ -190,6 +190,9 @@ class RsvFormsPage extends RsvAdminPage {
pattern: data.pattern ?? '',
pattern_message: data.pattern_message ?? '',
} : {}),
...(data.type === 'output-text' ? {
tag: data.tag ?? 'p',
} : {}),
...(data.type === 'reservation' ? {
timetable_id: data.timetable_id ? parseInt(data.timetable_id) : null,
price_per_block: parseFloat(data.price_per_block ?? '0') || 0,
@@ -262,6 +265,19 @@ class RsvFormsPage extends RsvAdminPage {
.input_textarea('email_refused_body', 'Body', refused.body ?? RSV_EMAIL_DEFAULTS.refused_body);
}
if ((data?.type ?? rsv_element_types[0]) === 'output-text') {
builder
.input_select('tag', 'Tag', [
{ value: 'p', label: 'Paragraph (p)' },
{ value: 'h1', label: 'Heading 1 (h1)' },
{ value: 'h2', label: 'Heading 2 (h2)' },
{ value: 'h3', label: 'Heading 3 (h3)' },
{ value: 'h4', label: 'Heading 4 (h4)' },
{ value: 'h5', label: 'Heading 5 (h5)' },
{ value: 'h6', label: 'Heading 6 (h6)' },
], data?.tag ?? 'p');
}
if ((data?.type ?? rsv_element_types[0]) === 'input-text') {
builder
.input_select('validation', 'Validation', [