mirror of
https://github.com/getgrav/grav-plugin-admin.git
synced 2026-01-06 15:43:01 +01:00
Allow plugins to provide pages in (plugin)/admin/pages/
This commit is contained in:
26
admin.php
26
admin.php
@@ -182,9 +182,29 @@ class AdminPlugin extends Plugin
|
||||
// Replace page service with admin.
|
||||
$this->grav['page'] = function () use ($self) {
|
||||
$page = new Page;
|
||||
$page->init(new \SplFileInfo(__DIR__ . "/pages/admin/{$self->template}.md"));
|
||||
$page->slug(basename($self->template));
|
||||
return $page;
|
||||
|
||||
if (file_exists(__DIR__ . "/pages/admin/{$self->template}.md")) {
|
||||
$page->init(new \SplFileInfo(__DIR__ . "/pages/admin/{$self->template}.md"));
|
||||
$page->slug(basename($self->template));
|
||||
return $page;
|
||||
}
|
||||
|
||||
// If the page cannot be found, try looking in plugins.
|
||||
// Allows pages added by plugins in admin
|
||||
$plugins = Grav::instance()['config']->get('plugins', []);
|
||||
|
||||
foreach($plugins as $plugin => $data) {
|
||||
$folder = GRAV_ROOT . "/user/plugins/" . $plugin . "/admin";
|
||||
|
||||
if (file_exists($folder)) {
|
||||
$file = $folder . "/pages/{$self->template}.md";
|
||||
if (file_exists($file)) {
|
||||
$page->init(new \SplFileInfo($file));
|
||||
$page->slug(basename($self->template));
|
||||
return $page;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user