Refactor HTMX fragment architecture: DRY split into auth endpoints + shared templates

- Created templates/partials/form/_licence.php (shared HTML, no auth logic)
- Created templates/partials/form/_format-website.php (shared HTML, no auth logic)
- Created src/FragmentRenderer.php helper for clean fragment rendering
- Created public/{admin,partage}/fragments/ subdirectories
- Created thin fragment endpoint files: auth guard + data fetch + render template
- Updated all hx-post references in templates to new fragments/ paths
- Updated partage/index.php routing for new fragments subdirectory
- Kept old fragment files as thin delegates for backward compat
- Updated nginx config: added PHP handler in /partage/ location block
This commit is contained in:
Pontoporeia
2026-05-12 15:01:17 +02:00
parent 2632730fa0
commit da153fc604
38 changed files with 503 additions and 527 deletions

View File

@@ -0,0 +1,48 @@
<?php
/**
* _format-website.php — Shared HTMX fragment template for the Site web fieldset.
*
* Returns the website URL + label inputs when "Site web" is among the selected
* format checkboxes. Pure presentation — receives all data via variables.
*
* Expected variables:
* string $fieldsetId — HTML id for the <fieldset> ('website-url-fieldset' or 'edit-website-url-fieldset')
* array $selectedFormats — selected format_type IDs
* int $websiteFormatId — ID of the "Site web" format_type
* string $websiteUrl — current value (for repopulation)
* string $websiteLabel — current value (for repopulation)
*/
if (!$websiteFormatId) {
echo '<fieldset id="' . $fieldsetId . '" style="display:none"></fieldset>';
return;
}
if (!in_array((int)$websiteFormatId, array_map('intval', $selectedFormats), true)) {
echo '<fieldset id="' . $fieldsetId . '" style="display:none"></fieldset>';
return;
}
$escUrl = htmlspecialchars($websiteUrl);
$escLabel = htmlspecialchars($websiteLabel);
?>
<fieldset id="<?= $fieldsetId ?>">
<legend>Site web</legend>
<div class="admin-form-group">
<label for="website_url">URL du site :</label>
<div class="admin-file-input">
<input type="url" id="website_url" name="website_url"
value="<?= $escUrl ?>"
placeholder="https://mon-tfe.erg.be">
<small>Si le TFE est un site web, entrez son URL ici. Il sera affiché comme un site embarqué sur la page du TFE.</small>
</div>
</div>
<div class="admin-form-group">
<label for="website_label">Légende :</label>
<input type="text" id="website_label" name="website_label"
value="<?= $escLabel ?>"
placeholder="Description du site (optionnel)"
class="admin-file-label-input"
style="max-width:400px;">
</div>
</fieldset>