mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-05-06 19:19:19 +02:00
centralise form fieldsets into shared partials; add TODO stubs in partage form
This commit is contained in:
63
app/templates/partials/form/fieldset-metadata.php
Normal file
63
app/templates/partials/form/fieldset-metadata.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
* Shared partial — "Métadonnées complémentaires" fieldset.
|
||||
*
|
||||
* Variables consumed:
|
||||
* callable|null $oldFn — callable($key, $default='') for old/current values.
|
||||
* callable|null $withAutofocusFn — callable($field, $attrs=[]) to inject autofocus.
|
||||
* array $licenseTypes — options for the license select.
|
||||
* array $enabledAccessTypes — raw access-type rows (with 'id', 'name', optionally 'description').
|
||||
* array $formData — raw form data (used for selected state).
|
||||
* int $defaultAccessTypeId — default access type id; defaults to 2.
|
||||
* bool $showDescription — when true, appends description to access-type option labels.
|
||||
*/
|
||||
|
||||
$oldFn = $oldFn ?? (function_exists('old') ? 'old' : fn($k, $d = '') => $d);
|
||||
$withAutofocusFn = $withAutofocusFn ?? fn($field, $attrs = []) => $attrs;
|
||||
$formData = $formData ?? [];
|
||||
$defaultAccessTypeId = $defaultAccessTypeId ?? 2;
|
||||
$showDescription = $showDescription ?? false;
|
||||
|
||||
$accessOptions = array_map(function ($at) use ($showDescription) {
|
||||
$label = $at['name'];
|
||||
if ($showDescription && !empty($at['description'])) {
|
||||
$label .= ' — ' . $at['description'];
|
||||
}
|
||||
return ['id' => $at['id'], 'name' => $label];
|
||||
}, $enabledAccessTypes);
|
||||
|
||||
$selectedAccessType = isset($formData['access_type_id'])
|
||||
? (int) $formData['access_type_id']
|
||||
: $defaultAccessTypeId;
|
||||
?>
|
||||
<fieldset>
|
||||
<legend>Métadonnées complémentaires</legend>
|
||||
|
||||
<?php
|
||||
$name = 'license_id'; $label = 'Licence :'; $options = $licenseTypes;
|
||||
$selected = $formData['license_id'] ?? ''; $placeholder = '— Inconnue —';
|
||||
include APP_ROOT . '/templates/partials/form/select-field.php';
|
||||
?>
|
||||
|
||||
<?php
|
||||
$name = 'duration_info'; $label = 'Durée / Taille :'; $value = $oldFn('duration_info');
|
||||
$placeholder = 'Ex : 84 pages'; $hint = 'Durée (minutes) ou nombre de pages.';
|
||||
include APP_ROOT . '/templates/partials/form/text-field.php';
|
||||
?>
|
||||
|
||||
<?php
|
||||
$name = 'lien'; $label = 'Lien (site / ressource) :'; $value = $oldFn('lien');
|
||||
$type = 'url'; $placeholder = 'https://...';
|
||||
$attrs = $withAutofocusFn('lien');
|
||||
include APP_ROOT . '/templates/partials/form/text-field.php';
|
||||
?>
|
||||
|
||||
<?php
|
||||
$name = 'access_type_id'; $label = 'Visibilité / Accès :';
|
||||
$options = $accessOptions; $selected = $selectedAccessType;
|
||||
$placeholder = null; $required = true; $attrs = [];
|
||||
include APP_ROOT . '/templates/partials/form/select-field.php';
|
||||
?>
|
||||
</fieldset>
|
||||
<?php
|
||||
unset($oldFn, $withAutofocusFn, $formData, $defaultAccessTypeId, $showDescription, $accessOptions, $selectedAccessType);
|
||||
Reference in New Issue
Block a user