pluginPath = dirname(__DIR__, 3); } public function routeWebRequestEventListener(RouteWebRequestEvent $event) { // If this request has nothing to do with the admin interface, don't bother routing the request if (substr($event->uriString, 0, strlen($this->pluginKey)) !== $this->pluginKey) return; Logger::log("Administration: observed admin request. Activating plugin."); // Load the dependencies $this->config = Factory::getInstance('config'); $this->router = Factory::getInstance('router'); $this->models = Factory::getInstance('models'); $this->views = Factory::getInstance('views'); $this->controllers = Factory::getInstance('controllers'); // Load the admin configuration $this->config->addComponentPath($this->pluginPath, Priority::LOWEST); $this->adminCFG = $this->config->getConfig('admin'); // If admin is not enabled, stop here if (!$this->adminCFG->get('admin_enabled')) return; // Now load the pluginKey $this->pluginKey = $this->adminCFG->get('admin_url'); // If it does, register everything /** @var Resources $resources */ $resources = Factory::getInstance('resources'); // Serve the AdminLTE distribution files $adminLTE = $this->pluginPath . DS . 'vendor' . DS . 'almasaeed2010' . DS . 'adminlte'; $resources->registerResources('admin/dist', $adminLTE . DS . 'dist'); $resources->registerResources('admin/plugins', $adminLTE . DS . 'plugins'); // And serve the actual pages $routeString = '^' . $this->pluginKey . '(|\/(?P.*?)(|\/(?P.*?)(|\/(?P.*?))))'; $this->router->addRoute($routeString, ['callable' => [$this, 'adminCallable']], Priority::HIGHEST); // And add componentPaths for models, views, controllers $this->models->addComponentPath($this->pluginPath . DS . 'models', Priority::LOW); $this->views->addComponentPath($this->pluginPath . DS . 'views', Priority::LOW); $this->controllers->addComponentPath($this->pluginPath . DS . 'controllers', Priority::LOW); } public function adminCallable(array $matches, string $routeString) { Logger::log("AdminCallable called. Loading admin page."); // Load layouts and assign componentPath, in case the loaded view needs access to it /** @var Layout $layouts */ $layouts = Factory::getInstance('layouts'); $layouts->addComponentPath($this->pluginPath . DS . 'layouts', Priority::LOW); // And add a layoutLoadEventListener, to add global administration variables Events::addListener([$this, 'layoutLoadEventListener'], 'layoutLoadEvent', Priority::NORMAL); // Let's generate the sidebar $finder = new PageFinder(); $sidebar = $finder->generateSidebar(); // Afterwards, pass on to the admin view and its contents Logger::log("Forwarding request to Router::defaultCallable()."); $matches['viewType'] = 'admin'; $content = $this->router->defaultCallable($matches, $routeString); // Reset and assign Logger::log("Generating panel wrapper."); $layouts->reset(false); $layouts->assign('sidebar', $sidebar); $layouts->assign('content', $content); // And load the page Logger::log("Forwarding output back to Router."); $page = $layouts->get('main/panel'); return $page; } /** * Listener for LayoutLoadEvent * * Assigns variables to Layout that this plugin's layouts may require. * * @param LayoutLoadEvent $event */ public function layoutLoadEventListener(LayoutLoadEvent $event) { $event->assign('adminKey', $this->pluginKey); } /** * @inheritDoc */ public function getName(): string { return 'FuzeWorksAdministration'; } /** * @inheritDoc */ public function getClassesPrefix(): ?string { return null; } /** * @inheritDoc */ public function getSourceDirectory(): ?string { return null; } /** * @inheritDoc */ public function getPluginClass(): ?string { return null; } }