mirror of
https://github.com/flarum/framework.git
synced 2024-12-02 23:23:52 +08:00
Frontend extender: Work without extension, too
This commit is contained in:
parent
a49f2204ab
commit
e8c779fcf4
|
@ -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';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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";
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user