mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-05-06 11:09:18 +02:00
64 lines
2.7 KiB
PHP
64 lines
2.7 KiB
PHP
<?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);
|