From 3647f6f0311e9d620d04b68c8858eb246502940b Mon Sep 17 00:00:00 2001 From: Philipp Date: Sun, 18 Jul 2021 22:36:06 +0200 Subject: [PATCH] Refactor storage admin setting --- src/Module/Admin/Storage.php | 49 ++++++++++++--------- view/templates/admin/storage.tpl | 11 ++++- view/theme/frio/templates/admin/storage.tpl | 40 +++++++++++++++++ 3 files changed, 77 insertions(+), 23 deletions(-) create mode 100644 view/theme/frio/templates/admin/storage.tpl diff --git a/src/Module/Admin/Storage.php b/src/Module/Admin/Storage.php index 1e1678b138..08d2df316b 100644 --- a/src/Module/Admin/Storage.php +++ b/src/Module/Admin/Storage.php @@ -25,7 +25,6 @@ use Friendica\Core\Renderer; use Friendica\DI; use Friendica\Module\BaseAdmin; use Friendica\Util\Strings; -use Psr\Log\LogLevel; class Storage extends BaseAdmin { @@ -35,11 +34,11 @@ class Storage extends BaseAdmin self::checkFormSecurityTokenRedirectOnError('/admin/storage', 'admin_storage'); - $storagebackend = Strings::escapeTags(trim($_POST['storagebackend'] ?? '')); + $storagebackend = Strings::escapeTags(trim($_POST['storagebackend'] ?? '')); // save storage backend form if (DI::storageManager()->setBackend($storagebackend)) { - $storage_opts = DI::storage()->getOptions(); + $storage_opts = DI::storage()->getOptions(); $storage_form_prefix = preg_replace('|[^a-zA-Z0-9]|', '', $storagebackend); $storage_opts_data = []; foreach ($storage_opts as $name => $info) { @@ -75,8 +74,9 @@ class Storage extends BaseAdmin { parent::content($parameters); - $current_storage_backend = DI::storage(); + $current_storage_backend = DI::storage(); $available_storage_backends = []; + $available_storage_forms = []; // show legacy option only if it is the current backend: // once changed can't be selected anymore @@ -86,14 +86,12 @@ class Storage extends BaseAdmin foreach (DI::storageManager()->listBackends() as $name => $class) { $available_storage_backends[$name] = $name; - } - // build storage config form, - $storage_form_prefix = preg_replace('|[^a-zA-Z0-9]|' ,'', $current_storage_backend); + // build storage config form, + $storage_form_prefix = preg_replace('|[^a-zA-Z0-9]|', '', $current_storage_backend); - $storage_form = []; - if (!is_null($current_storage_backend) && $current_storage_backend != '') { - foreach ($current_storage_backend->getOptions() as $name => $info) { + $storage_form = []; + foreach (DI::storageManager()->getByName($name)->getOptions() as $option => $info) { $type = $info[0]; // Backward compatibilty with yesno field description if ($type == 'yesno') { @@ -102,24 +100,31 @@ class Storage extends BaseAdmin unset($info[4]); } - $info[0] = $storage_form_prefix . '_' . $name; - $info['type'] = $type; - $info['field'] = 'field_' . $type . '.tpl'; - $storage_form[$name] = $info; + $info[0] = $storage_form_prefix . '_' . $option; + $info['type'] = $type; + $info['field'] = 'field_' . $type . '.tpl'; + $storage_form[$option] = $info; + } + + if (count($storage_form) > 0) { + $available_storage_forms[] = [ + 'name' => $name, + 'form' => $storage_form, + ]; } } $t = Renderer::getMarkupTemplate('admin/storage.tpl'); return Renderer::replaceMacros($t, [ - '$title' => DI::l10n()->t('Administration'), - '$page' => DI::l10n()->t('Storage'), - '$submit' => DI::l10n()->t('Save Settings'), - '$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], - '$storageform' => $storage_form, + '$title' => DI::l10n()->t('Administration'), + '$page' => DI::l10n()->t('Storage'), + '$submit' => DI::l10n()->t('Save Settings'), + '$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], + '$availablestorageforms' => $available_storage_forms, ]); } } diff --git a/view/templates/admin/storage.tpl b/view/templates/admin/storage.tpl index af4f1fbced..760d97a649 100644 --- a/view/templates/admin/storage.tpl +++ b/view/templates/admin/storage.tpl @@ -4,10 +4,19 @@
+

Storage Backend

+ {{include file="field_select.tpl" field=$storagebackend}} - {{foreach from=$storageform item=$field}} +
+ +

Storage Configuration

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

{{$storage.name}}

+ {{foreach from=$storage.form item=$field}} {{include file=$field.field field=$field}} {{/foreach}} + {{/foreach}}
diff --git a/view/theme/frio/templates/admin/storage.tpl b/view/theme/frio/templates/admin/storage.tpl new file mode 100644 index 0000000000..4174c071d2 --- /dev/null +++ b/view/theme/frio/templates/admin/storage.tpl @@ -0,0 +1,40 @@ + + +
+

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

+ + + + +

Storage Backend

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

Storage Configuration

+ + {{foreach from=$availablestorageforms item=$storage}} +
+ +
+
+ {{foreach from=$storage.form item=$field}} + {{include file=$field.field field=$field}} + {{/foreach}} +
+ +
+
+ + {{/foreach}} + + +