From e8c779fcf4ff6b14eaea5ea6c7fc85c7e2b46745 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Sat, 1 Sep 2018 16:15:02 +0200 Subject: [PATCH] Frontend extender: Work without extension, too --- framework/core/src/Extend/Frontend.php | 15 ++++++++++----- .../core/src/Frontend/Asset/ExtensionAssets.php | 15 ++++++--------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/framework/core/src/Extend/Frontend.php b/framework/core/src/Extend/Frontend.php index 171c9eaaa..2a305503d 100644 --- a/framework/core/src/Extend/Frontend.php +++ b/framework/core/src/Extend/Frontend.php @@ -53,11 +53,11 @@ class Frontend implements ExtenderInterface public function __invoke(Container $container, Extension $extension = null) { - $this->registerAssets($container, $extension); + $this->registerAssets($container, $this->getModuleName($extension)); $this->registerRoutes($container); } - private function registerAssets(Container $container, Extension $extension) + private function registerAssets(Container $container, string $moduleName) { if (empty($this->css) && empty($this->js)) { return; @@ -65,10 +65,10 @@ class Frontend implements ExtenderInterface $container->resolving( "flarum.$this->frontend.assets", - function (CompilerFactory $assets) use ($extension) { - $assets->add(function () use ($extension) { + function (CompilerFactory $assets) use ($moduleName) { + $assets->add(function () use ($moduleName) { return new ExtensionAssets( - $extension, $this->css, $this->js + $moduleName, $this->css, $this->js ); }); } @@ -91,4 +91,9 @@ class Frontend implements ExtenderInterface ); } } + + private function getModuleName(?Extension $extension): string + { + return $extension ? $extension->getId() : 'site-custom'; + } } diff --git a/framework/core/src/Frontend/Asset/ExtensionAssets.php b/framework/core/src/Frontend/Asset/ExtensionAssets.php index 64da87363..7dfcb407d 100644 --- a/framework/core/src/Frontend/Asset/ExtensionAssets.php +++ b/framework/core/src/Frontend/Asset/ExtensionAssets.php @@ -11,15 +11,14 @@ namespace Flarum\Frontend\Asset; -use Flarum\Extension\Extension; use Flarum\Frontend\Compiler\Source\SourceCollector; class ExtensionAssets implements AssetInterface { /** - * @var Extension + * @var string */ - protected $extension; + protected $moduleName; /** * @var array @@ -32,13 +31,13 @@ class ExtensionAssets implements AssetInterface protected $js; /** - * @param Extension $extension + * @param string $moduleName * @param array $css * @param string|callable|null $js */ - public function __construct(Extension $extension, array $css, $js = null) + public function __construct(string $moduleName, array $css, $js = null) { - $this->extension = $extension; + $this->moduleName = $moduleName; $this->css = $css; $this->js = $js; } @@ -57,9 +56,7 @@ class ExtensionAssets implements AssetInterface } $sources->addString(function () { - $name = $this->extension->getId(); - - return "flarum.extensions['$name']=module.exports"; + return "flarum.extensions['$this->moduleName']=module.exports"; }); } }