From efff254a3a001ba1205cfef41a257d72dc8115a3 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 27 Jun 2021 22:11:45 -0400 Subject: [PATCH] Wrap each addon settings form in their own form tag - The single form tag was preventing a given addon settings to be saved if another addon had an empty required field. - Instead of concatenating the addon form HTML through Hook::callAll, we loop manually through the hooks, appending the HTML to an array. --- mod/settings.php | 15 +++++++-------- view/templates/settings/addons.tpl | 13 ++++++++----- view/theme/frio/templates/settings/addons.tpl | 14 ++++++++++---- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/mod/settings.php b/mod/settings.php index b248f017e..c94490a87 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -502,21 +502,20 @@ function settings_content(App $a) } if (($a->argc > 1) && ($a->argv[1] === 'addon')) { - $settings_addons = ""; + $addon_settings_forms = []; - $r = q("SELECT * FROM `hook` WHERE `hook` = 'addon_settings' "); - if (!DBA::isResult($r)) { - $settings_addons = DI::l10n()->t('No Addon settings configured'); + foreach (DI::dba()->select('hook', ['file', 'function'], ['hook' => 'addon_settings']) as $hook) { + $data = ''; + Hook::callSingle(DI::app(), 'addon_settings', [$hook['file'], $hook['function']], $data); + $addon_settings_forms[] = $data; } - Hook::callAll('addon_settings', $settings_addons); - - $tpl = Renderer::getMarkupTemplate('settings/addons.tpl'); $o .= Renderer::replaceMacros($tpl, [ '$form_security_token' => BaseModule::getFormSecurityToken("settings_addon"), '$title' => DI::l10n()->t('Addon Settings'), - '$settings_addons' => $settings_addons + '$no_addons_settings_configured' => DI::l10n()->t('No Addon settings configured'), + '$addon_settings_forms' => $addon_settings_forms, ]); return $o; } diff --git a/view/templates/settings/addons.tpl b/view/templates/settings/addons.tpl index 567ac81b7..e30732d17 100644 --- a/view/templates/settings/addons.tpl +++ b/view/templates/settings/addons.tpl @@ -1,11 +1,14 @@ -

{{$title}}

+{{foreach $addon_settings_forms as $addon_settings_form}}
- - -{{$settings_addons nofilter}} - + + {{$addon_settings_form nofilter}}
+{{foreachelse}} + +

{{$no_addon_settings_configured}}

+ +{{/foreach}} diff --git a/view/theme/frio/templates/settings/addons.tpl b/view/theme/frio/templates/settings/addons.tpl index b14552381..f6e2d6108 100644 --- a/view/theme/frio/templates/settings/addons.tpl +++ b/view/theme/frio/templates/settings/addons.tpl @@ -2,11 +2,17 @@ {{* include the title template for the settings title *}} {{include file="section_title.tpl" title=$title}} +{{foreach $addon_settings_forms as $addon_settings_form}} +
- - - {{$settings_addons nofilter}} - + + {{$addon_settings_form nofilter}}
+{{foreachelse}} + + + +{{/foreach}} + \ No newline at end of file