summaryrefslogtreecommitdiffstats
path: root/inc
diff options
context:
space:
mode:
authorSimon Rettberg2025-07-18 16:35:46 +0200
committerSimon Rettberg2025-07-18 16:35:46 +0200
commita8d23f91f6cfd803be1ecaae4c8d1b5e1268a699 (patch)
tree58e3abdb7b915a5be041071c8a3324828ea596cf /inc
parent[locationinfo] Add UPCOMING panel type (diff)
downloadslx-admin-a8d23f91f6cfd803be1ecaae4c8d1b5e1268a699.tar.gz
slx-admin-a8d23f91f6cfd803be1ecaae4c8d1b5e1268a699.tar.xz
slx-admin-a8d23f91f6cfd803be1ecaae4c8d1b5e1268a699.zip
[locationinfo] Parametrize panel type configuration
Avoids a lot of copy and paste and duplicate work in php and html part, for example explicitly handling every config variable for a specific panel when displaying the config dialog, when saving the config, and when loading the config for displaying the panel. This also parametrizes enums, limits and ranges, so dropdowns can be rendered automatically, validity of selected option can be checked, and putting numeric settings into bounds all happens generically. Edit dialog for DEFAULT panel is still completely custom, as it has too much special sauce going on with the room config overrides. URL-panel is half-half, but SUMMARY and UPCOMING are entirely generic now.
Diffstat (limited to 'inc')
-rw-r--r--inc/request.inc.php11
1 files changed, 9 insertions, 2 deletions
diff --git a/inc/request.inc.php b/inc/request.inc.php
index 0b0600da..7edb8140 100644
--- a/inc/request.inc.php
+++ b/inc/request.inc.php
@@ -123,7 +123,14 @@ class Request
}
foreach ($params as $type => $list) {
foreach ($list as $field => $limits) {
- $default = $limits['default'] ?? false;
+ if ($type === 'bool') {
+ // An unchecked checkbox will not have its key in the post data, so self::handle would fall back
+ // to the default value. If the default is true, this would mean the parameter would be set to
+ // true, which is incorrect.
+ $default = false;
+ } else {
+ $default = $limits['default'] ?? false;
+ }
$value = self::handle($input, $field, $default, $type);
if (isset($limits['min']) && $value < $limits['min']) {
$value = $limits['min'];
@@ -132,7 +139,7 @@ class Request
$value = $limits['max'];
}
if (isset($limits['enum']) && !in_array($value, $limits['enum'])) {
- $value = array_shift($limits['enum']);
+ $value = $limits['default'] ?? array_shift($limits['enum']);
}
$out[$field] = $value;
}