diff --git a/platforms/grav/gantry5/gantry5.php b/platforms/grav/gantry5/gantry5.php index 7cf48cb8a..293bddf09 100644 --- a/platforms/grav/gantry5/gantry5.php +++ b/platforms/grav/gantry5/gantry5.php @@ -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], diff --git a/src/platforms/grav/Admin/Router.php b/src/platforms/grav/Admin/Router.php new file mode 100644 index 000000000..78d8c5895 --- /dev/null +++ b/src/platforms/grav/Admin/Router.php @@ -0,0 +1,62 @@ +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' + ]; + } +}