From e19b9824cdf523453d3c686d8a36a1182a83ebcd Mon Sep 17 00:00:00 2001 From: Philipp Date: Tue, 20 Jul 2021 23:33:35 +0200 Subject: [PATCH] Allow setting & saving storages per type --- src/Module/Admin/Storage.php | 26 +++++++++++---------- static/routes.config.php | 3 ++- view/templates/admin/storage.tpl | 19 +++++++-------- view/theme/frio/templates/admin/storage.tpl | 20 +++++++++------- 4 files changed, 36 insertions(+), 32 deletions(-) diff --git a/src/Module/Admin/Storage.php b/src/Module/Admin/Storage.php index 689f67d372..6b07cf5b05 100644 --- a/src/Module/Admin/Storage.php +++ b/src/Module/Admin/Storage.php @@ -35,7 +35,8 @@ class Storage extends BaseAdmin self::checkFormSecurityTokenRedirectOnError('/admin/storage', 'admin_storage'); - $storagebackend = Strings::escapeTags(trim($_POST['storagebackend'] ?? '')); + $storagebackend = Strings::escapeTags(trim($parameters['name'] ?? '')); + /** @var IStorage $newstorage */ $newstorage = DI::storageManager()->getByName($storagebackend); @@ -66,8 +67,10 @@ class Storage extends BaseAdmin DI::baseUrl()->redirect('admin/storage'); } - if (empty($storagebackend) || !DI::storageManager()->setBackend($storagebackend)) { - notice(DI::l10n()->t('Invalid storage backend setting value.')); + if (!empty($_POST['submit_save_set'])) { + if (empty($storagebackend) || !DI::storageManager()->setBackend($storagebackend)) { + notice(DI::l10n()->t('Invalid storage backend setting value.')); + } } DI::baseUrl()->redirect('admin/storage'); @@ -109,13 +112,11 @@ class Storage extends BaseAdmin $storage_form[$option] = $info; } - if (count($storage_form) > 0) { - $available_storage_forms[] = [ - 'name' => $name, - 'prefix' => $storage_form_prefix, - 'form' => $storage_form, - ]; - } + $available_storage_forms[] = [ + 'name' => $name, + 'prefix' => $storage_form_prefix, + 'form' => $storage_form, + ]; } $t = Renderer::getMarkupTemplate('admin/storage.tpl'); @@ -123,11 +124,12 @@ class Storage extends BaseAdmin return Renderer::replaceMacros($t, [ '$title' => DI::l10n()->t('Administration'), '$page' => DI::l10n()->t('Storage'), - '$submit' => DI::l10n()->t('Save Settings'), + '$save' => DI::l10n()->t('Save Settings'), + '$save_set' => DI::l10n()->t('Set Backend'), '$clear' => DI::l10n()->t('Clear'), '$baseurl' => DI::baseUrl()->get(true), '$form_security_token' => self::getFormSecurityToken("admin_storage"), - '$storagebackend' => ['storagebackend', DI::l10n()->t('File storage backend'), $current_storage_backend, DI::l10n()->t('The backend used to store uploaded data. If you change the storage backend, you can manually move the existing files. If you do not do so, the files uploaded before the change will still be available at the old backend. Please see the settings documentation for more information about the choices and the moving procedure.'), $available_storage_backends], + '$storagebackend' => $current_storage_backend, '$availablestorageforms' => $available_storage_forms, ]); } diff --git a/static/routes.config.php b/static/routes.config.php index 05e266ff10..74cc59df81 100644 --- a/static/routes.config.php +++ b/static/routes.config.php @@ -198,7 +198,8 @@ return [ '/site' => [Module\Admin\Site::class, [R::GET, R::POST]], - '/storage' => [Module\Admin\Storage::class, [R::GET, R::POST]], + '/storage' => [Module\Admin\Storage::class, [R::GET, R::POST]], + '/storage/{name}' => [Module\Admin\Storage::class, [ R::POST]], '/themes' => [Module\Admin\Themes\Index::class, [R::GET, R::POST]], '/themes/{theme}' => [Module\Admin\Themes\Details::class, [R::GET, R::POST]], diff --git a/view/templates/admin/storage.tpl b/view/templates/admin/storage.tpl index 10bdb1e0f8..bfe6511bf0 100644 --- a/view/templates/admin/storage.tpl +++ b/view/templates/admin/storage.tpl @@ -1,24 +1,23 @@

{{$title}} - {{$page}}

-
- - -

Storage Backend

- - {{include file="field_select.tpl" field=$storagebackend}} -
+

Current Storage Backend: {{$storagebackend}}

Storage Configuration

{{foreach from=$availablestorageforms item=$storage}} + +

{{$storage.name}}

{{foreach from=$storage.form item=$field}} {{include file=$field.field field=$field}} {{/foreach}} + + {{if $storage.form}} +
+ {{/if}} +
+
{{/foreach}} -
- -
diff --git a/view/theme/frio/templates/admin/storage.tpl b/view/theme/frio/templates/admin/storage.tpl index ed889bf1d8..0827c06acf 100644 --- a/view/theme/frio/templates/admin/storage.tpl +++ b/view/theme/frio/templates/admin/storage.tpl @@ -3,19 +3,17 @@

{{$title}} - {{$page}}

-
- - -

Storage Backend

- - {{include file="field_select.tpl" field=$storagebackend}} - +
+ Current Storage Backend: {{$storagebackend}} +

Storage Configuration

{{foreach from=$availablestorageforms item=$storage}} + +