From 536beb0f81f91ddad604fe8861174eaa8a9de55f Mon Sep 17 00:00:00 2001 From: evrifaessa Date: Mon, 14 Nov 2022 15:04:02 +0300 Subject: [PATCH] Reworked the settings and introduced new endpoints --- src/bb-library/Box/Mod.php | 32 ++++++++++++ src/bb-modules/Extension/Service.php | 12 +++-- .../html/mod_system_index.html.twig | 49 +++++++++---------- 3 files changed, 63 insertions(+), 30 deletions(-) mode change 100644 => 100755 src/bb-themes/admin_default/html/mod_system_index.html.twig diff --git a/src/bb-library/Box/Mod.php b/src/bb-library/Box/Mod.php index 19280f8e3..9147fdd81 100644 --- a/src/bb-library/Box/Mod.php +++ b/src/bb-library/Box/Mod.php @@ -157,6 +157,38 @@ class Box_Mod return file_exists($this->_getModPath() . 'html_admin/mod_'.$this->mod.'_settings.html.twig'); } + public function hasSettingsRoutes() + { + if($this->hasService()) { + $s = $this->getService(); + if(method_exists($s, 'getSettingsRoutes')) { + return (count($s->getSettingsRoutes()) > 0); + } + } + + return false; + } + + public function getSettingsRoutes() + { + $result = array(); + + if ($this->hasSettingsRoutes()) { + foreach ($this->getService()->getSettingsRoutes() as $route) { + // Check if it is a valid external link + $filtered = filter_var(idn_to_ascii($route["path"]), FILTER_VALIDATE_URL); + + // If it's an external link, return it directly. Otherwise, return the internal link with the /admin prefix. + $route['path'] = $filtered ? $filtered : $this->di['url']->adminLink($route["path"], []); + $result[] = $route; + } + + return $result; + } else { + return array(); + } + } + public function hasAdminController() { return file_exists($this->_getModPath() . 'Controller/Admin.php'); diff --git a/src/bb-modules/Extension/Service.php b/src/bb-modules/Extension/Service.php index c391691e6..6cb612868 100644 --- a/src/bb-modules/Extension/Service.php +++ b/src/bb-modules/Extension/Service.php @@ -133,6 +133,8 @@ class Service implements InjectionAwareInterface $manifest = $m->getManifest(); $manifest['status'] = 'core'; $manifest['has_settings'] = $m->hasSettingsPage(); + $manifest['has_settings_routes'] = $m->hasSettingsRoutes(); + $manifest['settings_routes'] = $m->hasSettingsRoutes() ? $m->getSettingsRoutes() : array(); $result[] = $manifest; } } @@ -147,10 +149,10 @@ class Service implements InjectionAwareInterface $manifest['version'] = $im['version']; $manifest['status'] = $im['status']; - if ('mod' == $im['type'] && 'installed' == $im['status'] && $m->hasSettingsPage()) { - $manifest['has_settings'] = true; - } else { - $manifest['has_settings'] = false; + if ('mod' == $im['type'] && 'installed' == $im['status']) { + $manifest['has_settings'] = $m->hasSettingsPage(); + $manifest['has_settings_routes'] = $m->hasSettingsRoutes(); + $manifest['settings_routes'] = $m->hasSettingsRoutes() ? $m->getSettingsRoutes() : array(); } $result[] = $manifest; @@ -173,6 +175,8 @@ class Service implements InjectionAwareInterface $manifest = $m->getManifest(); $manifest['status'] = null; $manifest['has_settings'] = false; + $manifest['has_settings_routes'] = false; + $manifest['settings_routes'] = array(); $result[] = $manifest; } diff --git a/src/bb-themes/admin_default/html/mod_system_index.html.twig b/src/bb-themes/admin_default/html/mod_system_index.html.twig old mode 100644 new mode 100755 index 128230151..871825724 --- a/src/bb-themes/admin_default/html/mod_system_index.html.twig +++ b/src/bb-themes/admin_default/html/mod_system_index.html.twig @@ -9,32 +9,29 @@ {% block content %}
-
-
- {% include 'partial_search.html.twig' %} - - - {% for ext in admin.extension_get_list({ 'active': 1, 'has_settings': 1 }|merge(request)) %} - - - - - - {% endfor %} - -
- - {{ ext.name }} - - - {{ ext.name }} - - - - - - -
+
+

Settings

+
+
+
+ {% for ext in admin.extension_get_list({ 'active': 1, 'has_settings': 1 }|merge(request)) %} +
+ +
+
    + {% for route in ext.settings_routes %} +
  • + {{route.label}} +
  • + {% endfor %} +
+
+
+ {% endfor %}