Frontend extender: Remove route registration

This can be achieved using the Route extender, which is more
flexible, as it does not necessary connect the URL with the current
frontend's router.

(Example use-case: The ext-embed frontend will be a new frontend,
however any routes using this frontend will be part of the forum
route group.)

Refs #851.
This commit is contained in:
Franz Liedke 2018-09-07 01:29:13 +02:00
parent c61badd754
commit 4770a5c906
No known key found for this signature in database
GPG Key ID: 9A0231A879B055F4

View File

@ -14,7 +14,6 @@ namespace Flarum\Extend;
use Flarum\Extension\Extension;
use Flarum\Frontend\Asset\ExtensionAssets;
use Flarum\Frontend\CompilerFactory;
use Flarum\Http\RouteHandlerFactory;
use Illuminate\Contracts\Container\Container;
class Frontend implements ExtenderInterface
@ -44,17 +43,9 @@ class Frontend implements ExtenderInterface
return $this;
}
public function route($path, $name, $content = null)
{
$this->routes[] = compact('path', 'name', 'content');
return $this;
}
public function __invoke(Container $container, Extension $extension = null)
{
$this->registerAssets($container, $this->getModuleName($extension));
$this->registerRoutes($container);
}
private function registerAssets(Container $container, string $moduleName)
@ -75,23 +66,6 @@ class Frontend implements ExtenderInterface
);
}
private function registerRoutes(Container $container)
{
if (empty($this->routes)) {
return;
}
$routes = $container->make("flarum.$this->frontend.routes");
$factory = $container->make(RouteHandlerFactory::class);
foreach ($this->routes as $route) {
$routes->get(
$route['path'], $route['name'],
$factory->toFrontend($this->frontend, $route['content'])
);
}
}
private function getModuleName(?Extension $extension): string
{
return $extension ? $extension->getId() : 'site-custom';