Files
xamxam/templates/partials/form/checkbox-list.php
Pontoporeia 2143869b1e Add admin form field partials and apply to add/edit forms
Four reusable PHP partials extracted to templates/partials/form/:

- text-field.php  — single-line input (text/number/url); wraps input+hint in div,
                    skips the inner wrapper when no hint is present. Supports $type,
                    $placeholder, $required, $attrs, $hint, $id overrides.
- select-field.php — <select> with leading empty option; matches $selected against
                    option id OR option name string (handles view-sourced data where
                    orientation/ap/finality come back as name strings, not FK ids).
- checkbox-list.php — checkbox group (languages, formats); renders .admin-checkbox-list
                    with typed-string comparison so int ids from DB match string values.
- file-field.php  — file input with accept/multiple/hint; appends [] to name when
                    $multiple is true.

Both add.php and edit.php rewritten to use the partials:
- ~15 repeated text-field divs collapsed to single-line include calls
- ~6 repeated select divs collapsed to single-line include calls
- 4 checkbox-list blocks collapsed to 2 calls each
- 3 file input blocks collapsed to single-line include calls
- Textarea fields (synopsis, context_note) kept inline — no partial for <textarea>
- Banner preview block in edit.php kept inline — conditional UI not generalised

Line count: add.php 251→93 (-158), edit.php 289→171 (-118)
2026-04-02 12:48:04 +02:00

30 lines
1.1 KiB
PHP

<?php
/**
* Checkbox list partial — renders a group of checkboxes (e.g. languages, formats).
*
* Variables consumed:
* string $name — input name attribute (will be posted as array: name[])
* string $label — group label (rendered as plain <label>, not associated with any single input)
* array $options — each element must have 'id' and 'name' keys
* array $checked — array of 'id' values that are currently checked
*/
$checked = $checked ?? [];
?>
<div>
<label><?= htmlspecialchars($label) ?></label>
<div class="admin-checkbox-list">
<?php foreach ($options as $opt): ?>
<label class="admin-checkbox-label">
<input type="checkbox"
name="<?= htmlspecialchars($name) ?>[]"
value="<?= htmlspecialchars((string)$opt['id']) ?>"
<?= in_array((string)$opt['id'], array_map('strval', $checked)) ? 'checked' : '' ?>>
<?= htmlspecialchars($opt['name']) ?>
</label>
<?php endforeach; ?>
</div>
</div>
<?php
unset($checked);