refactor(settings): split admin/settings into hub + per-section subpages
Splits the 755-line monolithic settings page into a tile-based landing hub and six focused subpages (general, security, email, api, sso, branding), each with its own form, CSRF scope and POST handler. Each subpage offers Save / Save & close buttons plus a Cancel/back link to the hub. Backend (AdminSettingsService, gateways, policies, DB schema) unchanged. A new settingsSectionMergePost() helper overlays section POSTs onto the current DB values so partial saves don't wipe unrelated fields (the service defaults missing keys to 0/empty). Sub-action files (logo/favicon/tokens/lifecycle) redirect to the matching subpage, and architecture contracts now check the subpage files instead of the removed monolithic index. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
47
core/Support/helpers/admin_settings.php
Normal file
47
core/Support/helpers/admin_settings.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Merge a single-section POST body with current DB values so that
|
||||
* AdminSettingsService::updateFromAdmin() only updates the fields owned
|
||||
* by that section.
|
||||
*
|
||||
* Why this exists:
|
||||
* updateFromAdmin() reads all known keys from the POST array and defaults
|
||||
* missing keys to 0/empty/false (see sanitize* methods). Subpages that post
|
||||
* only their own fields would otherwise wipe unrelated sections. This helper
|
||||
* overlays the section's POST fields onto the current DB values formatted as
|
||||
* POST scalars, preserving checkbox semantics (omitted key = unchecked).
|
||||
*
|
||||
* @param array<string, mixed> $currentValues 'values' map from buildPageData()
|
||||
* @param array<string, mixed> $post user POST body (bodyAll())
|
||||
* @param list<string> $sectionKeys keys owned by this section
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
function settingsSectionMergePost(array $currentValues, array $post, array $sectionKeys): array
|
||||
{
|
||||
$seed = [];
|
||||
foreach ($currentValues as $key => $value) {
|
||||
if (is_bool($value)) {
|
||||
if ($value) {
|
||||
$seed[$key] = '1';
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (is_array($value)) {
|
||||
$seed[$key] = $value;
|
||||
continue;
|
||||
}
|
||||
if ($value !== null) {
|
||||
$seed[$key] = (string) $value;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($sectionKeys as $key) {
|
||||
unset($seed[$key]);
|
||||
if (array_key_exists($key, $post)) {
|
||||
$seed[$key] = $post[$key];
|
||||
}
|
||||
}
|
||||
|
||||
return $seed;
|
||||
}
|
||||
Reference in New Issue
Block a user