From 7bc5d8989ff753ceb8bfd825d000994089a5fb62 Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Thu, 6 Apr 2023 23:27:30 +0200 Subject: [PATCH] add options to sort modules and show distributed modules --- src/Config.php | 11 +++++++++++ src/Manage.php | 15 ++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/Config.php b/src/Config.php index 966f937..c6ba619 100644 --- a/src/Config.php +++ b/src/Config.php @@ -24,6 +24,7 @@ use Dotclear\Helper\Html\Form\{ Label, Legend, Para, + Select, Text }; use Exception; @@ -61,6 +62,8 @@ class Config extends dcNsProcess } dcCore::app()->blog->settings->get(My::id())->put('disabled', $pdisabled); dcCore::app()->blog->settings->get(My::id())->put('nodetails', !empty($_POST['nodetails'])); + dcCore::app()->blog->settings->get(My::id())->put('allow_distrib', !empty($_POST['allow_distrib'])); + dcCore::app()->blog->settings->get(My::id())->put('combosortby', $_POST['combosortby'] ?: 'name'); dcPage::addSuccessNotice(__('Configuration successfully updated')); @@ -103,6 +106,14 @@ class Config extends dcNsProcess (new Checkbox('nodetails', (bool) dcCore::app()->blog->settings->get(My::id())->get('nodetails')))->value('1'), (new Label(__('Hide details of rendered actions'), Label::OUTSIDE_LABEL_AFTER))->class('classic')->for('nodetails'), ]), + (new Para())->items([ + (new Checkbox('allow_distrib', (bool) dcCore::app()->blog->settings->get(My::id())->get('allow_distrib')))->value('1'), + (new Label(__('Show dotclear distributed modules'), Label::OUTSIDE_LABEL_AFTER))->class('classic')->for('allow_distrib'), + ]), + (new Para())->items([ + (new Label(__('Sort modules seletion by:')))->for('combosortby'), + (new Select('combosortby'))->items([__('Name') => 'name', __('Id') => 'id'])->default(dcCore::app()->blog->settings->get(My::id())->get('combosortby')), + ]), ]), ])->render(); } diff --git a/src/Manage.php b/src/Manage.php index da869b6..409ce53 100644 --- a/src/Manage.php +++ b/src/Manage.php @@ -129,13 +129,22 @@ class Manage extends dcNsProcess } $combo_modules = []; - foreach (self::$type == 'plugin' ? dcCore::app()->plugins->getDefines() : dcCore::app()->themes->getDefines() as $module) { + $modules = self::$type == 'plugin' ? dcCore::app()->plugins->getDefines() : dcCore::app()->themes->getDefines(); + if (dcCore::app()->blog->settings->get(My::id())->get('combosortby') == 'id') { + uasort($modules, fn ($a, $b) => strtolower($a->getId()) <=> strtolower($b->getId())); + } else { + uasort($modules, fn ($a, $b) => strtolower(dcUtils::removeDiacritics($a->get('name'))) <=> strtolower(dcUtils::removeDiacritics($b->get('name')))); + } + foreach ($modules as $module) { if (!$module->get('root_writable') || !dcCore::app()->blog->settings->get(My::id())->get('allow_distrib') && $module->get('distributed')) { continue; } - $combo_modules[sprintf(__('%s (%s)'), __($module->get('name')), $module->getId())] = $module->getId(); + if (dcCore::app()->blog->settings->get(My::id())->get('combosortby') == 'id') { + $combo_modules[sprintf(__('%s (%s)'), $module->getId(), __($module->get('name')))] = $module->getId(); + } else { + $combo_modules[sprintf(__('%s (%s)'), __($module->get('name')), $module->getId())] = $module->getId(); + } } - dcUtils::lexicalKeySort($combo_modules); return array_merge([__('Select a module') => '-'], $combo_modules); }