Skip to content

Commit ee0dcf8

Browse files
committed
Remove hardcoded admin paths from report URLs
1 parent 5f7c2c3 commit ee0dcf8

2 files changed

Lines changed: 17 additions & 7 deletions

File tree

classes/ReportUtil.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,20 @@ function render(&$tree, $level, &$s)
131131
return "<div class='report-tree'>" . $s . "</div>";
132132
}
133133

134+
public static function getAdminBaseRelative()
135+
{
136+
$config = \Grav\Common\Grav::instance()['config'];
137+
$route = $config->get('plugins.admin.route');
138+
$base = '/' . trim($route, '/');
139+
return $config->grav['base_url_relative'] . $base;
140+
// $admin_base = '/' . trim($config->get('plugins.admin.route'), '/');
141+
// $admin_base = trim($config->get('plugins.admin.route'), '/');
142+
// return $admin_base;
143+
}
144+
134145
public static function edit_link($page, $text)
135146
{
136-
$base = \Grav\Common\Grav::instance()['base_url_relative'];
137-
$href = $base . "/admin/pages" . $page->route();
147+
$href = self::getAdminBaseRelative() . "/pages" . $page->route();
138148
return "<a href='$href'>" . $text . "</a>";
139149
}
140150

@@ -155,7 +165,7 @@ public static function view_url($page)
155165
public static function edit_url($page)
156166
{
157167
$base = \Grav\Common\Grav::instance()['base_url_relative'];
158-
$href = $base . "/admin/pages" . $page->route();
168+
$href = self:: getAdminBaseRelative() . "/pages" . $page->route();
159169
return $href;
160170
}
161171

@@ -211,7 +221,7 @@ public static function getUnusedMedia()
211221
$unused[$path] = $html;
212222
// $unused[$path] = [
213223
// "page" => ,
214-
// "preview" =>
224+
// "preview" =>
215225
// ];
216226
}
217227
}
@@ -306,4 +316,4 @@ public static function isCachedPath($page)
306316
{
307317
return preg_match(self::rxCached, $page);
308318
}
309-
}
319+
}

services/reports.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ function array_find($filter, $array)
7272
}
7373
]);
7474

75-
$url = \Grav\Common\Grav::instance()['base_url_relative'];
76-
$url .= "/admin/admin-power-tools/reports";
75+
$url = ReportUtil::getAdminBaseRelative();
76+
$url .= "/admin-power-tools/reports";
7777
$manager->registerService('action', [
7878
"caption" => "Reports",
7979
"icon" => "fa-list",

0 commit comments

Comments
 (0)