From b8b0e683b4908f892ed6a53f43514af42ab8825a Mon Sep 17 00:00:00 2001
From: Jan-Hendrik Willms <tleilax+studip@gmail.com>
Date: Thu, 5 May 2022 15:19:10 +0000
Subject: [PATCH] allow open global section and jump to last configured item

Closes #1013 and #1014

Merge request studip/studip!586
---
 app/controllers/admin/configuration.php     | 10 ++++++++--
 app/views/admin/configuration/table-row.php |  2 +-
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/app/controllers/admin/configuration.php b/app/controllers/admin/configuration.php
index 1e6b3c352fe..4cfc0a3cd96 100644
--- a/app/controllers/admin/configuration.php
+++ b/app/controllers/admin/configuration.php
@@ -36,6 +36,12 @@ class Admin_ConfigurationController extends AuthenticatedController
         }
 
         $this->setupSidebar($this->range_type);
+
+        // Preserve section parameter
+        // This *must* be after the sidebar has been defined
+        if (!Request::isPost() && Request::submitted('section')) {
+            URLHelper::addLinkParam('section', Request::option('section'));
+        }
     }
 
     /**
@@ -61,7 +67,7 @@ class Admin_ConfigurationController extends AuthenticatedController
 
         // set variables for view
         $this->only_section = $section;
-        $this->open_section = $open_section ?: $section;
+        $this->open_section = $open_section ?? $section;
         $this->needle = $needle;
         $this->sections = ConfigurationModel::getConfig($section, $needle);
 
@@ -97,7 +103,7 @@ class Admin_ConfigurationController extends AuthenticatedController
                     htmlReady($field)
                 ));
 
-                $this->relocate('admin/configuration/configuration/' . $section);
+                $this->relocate("admin/configuration/configuration/{$section}#field-{$field}");
                 return;
             }
         }
diff --git a/app/views/admin/configuration/table-row.php b/app/views/admin/configuration/table-row.php
index fd57331171a..ef161e30cf1 100644
--- a/app/views/admin/configuration/table-row.php
+++ b/app/views/admin/configuration/table-row.php
@@ -1,4 +1,4 @@
-<tr>
+<tr id="field-<?= htmlReady($field) ?>">
     <td>
         <a data-dialog href="<?= $controller->link_for($linkchunk, compact('field')) ?>">
             <?= htmlReady($field) ?>
-- 
GitLab