mirror of
https://github.com/gantry/gantry5.git
synced 2026-08-19 01:15:04 -05:00
Grav: Implement admin router
This commit is contained in:
@@ -2,7 +2,10 @@
|
||||
namespace Grav\Plugin;
|
||||
|
||||
use Composer\Autoload\ClassLoader;
|
||||
use Gantry\Admin\Router;
|
||||
use Gantry\Framework\Base\ThemeTrait;
|
||||
use Gantry\Framework\Gantry;
|
||||
use Gantry5\Loader;
|
||||
use Grav\Common\Page\Page;
|
||||
use Grav\Common\Plugin;
|
||||
use Grav\Common\Themes;
|
||||
@@ -22,7 +25,7 @@ class Gantry5Plugin extends Plugin
|
||||
return [
|
||||
'onPluginsInitialized' => [
|
||||
['initialize', 1000],
|
||||
['detectAdmin', 900]
|
||||
['detectGantryAdmin', 900]
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -39,7 +42,7 @@ class Gantry5Plugin extends Plugin
|
||||
*
|
||||
* Disables system cache.
|
||||
*/
|
||||
public function detectAdmin()
|
||||
public function detectGantryAdmin()
|
||||
{
|
||||
if (!isset($this->grav['admin'])) {
|
||||
return;
|
||||
@@ -51,6 +54,10 @@ class Gantry5Plugin extends Plugin
|
||||
return;
|
||||
}
|
||||
|
||||
if (!defined('GANTRYADMIN_PATH')) {
|
||||
define('GANTRYADMIN_PATH', __DIR__);
|
||||
}
|
||||
|
||||
$base = rtrim($this->grav['base_url'], '/');
|
||||
$results = explode('/', $admin->route, 3);
|
||||
$theme = array_shift($results);
|
||||
@@ -72,14 +79,16 @@ class Gantry5Plugin extends Plugin
|
||||
return;
|
||||
}
|
||||
|
||||
$gantry = \Gantry\Framework\Gantry::instance();
|
||||
$gantry = Gantry::instance();
|
||||
$gantry['base_url'] = $this->base;
|
||||
$gantry['routes'] = [
|
||||
'1' => '/%s',
|
||||
'about' => ''
|
||||
];
|
||||
$gantry['router'] = function ($c) {
|
||||
return new Router($c);
|
||||
};
|
||||
|
||||
$this->grav['gantry'] = $gantry;
|
||||
// Dispatch to the controller.
|
||||
//$gantry['router']->dispatch();
|
||||
|
||||
$this->grav['gantry5'] = $gantry;
|
||||
|
||||
$this->enable([
|
||||
'onPagesInitialized' => ['onPagesInitialized', 900],
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
namespace Gantry\Admin;
|
||||
|
||||
use Gantry\Component\Request\Request;
|
||||
use Gantry\Component\Router\Router as BaseRouter;
|
||||
use Grav\Common\GPM\Remote\Grav;
|
||||
use Grav\Common\Uri;
|
||||
|
||||
class Router extends BaseRouter
|
||||
{
|
||||
public function boot()
|
||||
{
|
||||
$grav = Grav::getGrav();
|
||||
|
||||
/** @var Uri $uri */
|
||||
$uri = $grav['uri'];
|
||||
|
||||
/** @var \Grav\Plugin\Admin $admin */
|
||||
$admin = $grav['admin'];
|
||||
|
||||
/** @var Request $request */
|
||||
$request = $this->container['request'];
|
||||
|
||||
$theme = isset($this->container['theme.name']) ? $this->container['theme.name'] : '';
|
||||
|
||||
if ($theme) {
|
||||
$this->container['theme.path'] = GRAV_ROOT . '/themes/' . $theme;
|
||||
$this->container['theme.name'] = $theme;
|
||||
}
|
||||
|
||||
$this->load();
|
||||
|
||||
$parts = array_filter(explode('/', $admin->route), function($var) { return $var !== ''; });
|
||||
|
||||
// Second parameter is the resource.
|
||||
$this->resource = array_shift($parts) ?: 'about';
|
||||
|
||||
// Figure out the action we want to make.
|
||||
$this->method = $request->getMethod();
|
||||
$this->path = $parts;
|
||||
$this->format = $uri->extension('html');
|
||||
$ajax = ($this->format == 'json');
|
||||
|
||||
$this->params = [
|
||||
'ajax' => $ajax,
|
||||
'location' => $this->resource,
|
||||
'method' => $this->method,
|
||||
'format' => $this->format,
|
||||
'params' => isset($_POST['params']) && is_string($_POST['params']) ? json_decode($_POST['params'], true) : []
|
||||
];
|
||||
|
||||
$this->container['ajax_suffix'] = '.json';
|
||||
|
||||
$this->container['routes'] = [
|
||||
'1' => '/%s',
|
||||
'themes' => '',
|
||||
|
||||
'picker/layouts' => '/layouts',
|
||||
'picker/particles' => '/particles'
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user