mirror of
https://github.com/flarum/core.git
synced 2025-10-12 15:34:26 +02:00
Refactor frontend code to allow for extension of assets
- Simpler class naming: Frontend\CompilerFactory → Frontend\Assets Frontend\HtmlDocumentFactory → Frontend\Frontend Frontend\HtmlDocument → Frontend\Document - Remove AssetInterface and simply collect callbacks in Frontend\Assets instead - Remove ContentInterface because it serves no purpose (never type- hinted or type-checked) - Commit and add asset URLs to the Document via a content callback instead of in the Document factory class itself - Add translations and locale assets to Assets separate to the assets factory, as non-forum/admin asset bundles probably won't want them - Update Frontend Extender to allow the creation of new asset bundles - Make custom LESS validation listener a standalone class instead of extending RecompileFrontendAssets
This commit is contained in:
@@ -14,6 +14,9 @@ namespace Flarum\Admin;
|
||||
use Flarum\Event\ConfigureMiddleware;
|
||||
use Flarum\Foundation\AbstractServiceProvider;
|
||||
use Flarum\Foundation\Application;
|
||||
use Flarum\Frontend\AddLocaleAssets;
|
||||
use Flarum\Frontend\AddTranslations;
|
||||
use Flarum\Frontend\Compiler\Source\SourceCollector;
|
||||
use Flarum\Frontend\RecompileFrontendAssets;
|
||||
use Flarum\Http\Middleware as HttpMiddleware;
|
||||
use Flarum\Http\RouteCollection;
|
||||
@@ -62,17 +65,31 @@ class AdminServiceProvider extends AbstractServiceProvider
|
||||
$pipe->pipe(new HttpMiddleware\DispatchRoute($this->app->make('flarum.admin.routes')));
|
||||
});
|
||||
|
||||
$this->app->bind('flarum.admin.assets', function () {
|
||||
return $this->app->make('flarum.frontend.assets.defaults')('admin');
|
||||
$this->app->bind('flarum.assets.admin', function () {
|
||||
/** @var \Flarum\Frontend\Assets $assets */
|
||||
$assets = $this->app->make('flarum.assets.factory')('admin');
|
||||
|
||||
$assets->js(function (SourceCollector $sources) {
|
||||
$sources->addFile(__DIR__.'/../../js/dist/admin.js');
|
||||
});
|
||||
|
||||
$assets->css(function (SourceCollector $sources) {
|
||||
$sources->addFile(__DIR__.'/../../less/admin.less');
|
||||
});
|
||||
|
||||
$this->app->make(AddTranslations::class)->forFrontend('admin')->to($assets);
|
||||
$this->app->make(AddLocaleAssets::class)->to($assets);
|
||||
|
||||
return $assets;
|
||||
});
|
||||
|
||||
$this->app->bind('flarum.admin.frontend', function () {
|
||||
$view = $this->app->make('flarum.frontend.view.defaults')('admin');
|
||||
$this->app->bind('flarum.frontend.admin', function () {
|
||||
/** @var \Flarum\Frontend\Frontend $frontend */
|
||||
$frontend = $this->app->make('flarum.frontend.factory')('admin');
|
||||
|
||||
$view->setAssets($this->app->make('flarum.admin.assets'));
|
||||
$view->add($this->app->make(Content\AdminPayload::class));
|
||||
$frontend->content($this->app->make(Content\AdminPayload::class));
|
||||
|
||||
return $view;
|
||||
return $frontend;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -87,7 +104,7 @@ class AdminServiceProvider extends AbstractServiceProvider
|
||||
|
||||
$this->app->make('events')->subscribe(
|
||||
new RecompileFrontendAssets(
|
||||
$this->app->make('flarum.admin.assets'),
|
||||
$this->app->make('flarum.assets.admin'),
|
||||
$this->app->make('flarum.locales')
|
||||
)
|
||||
);
|
||||
|
@@ -12,8 +12,7 @@
|
||||
namespace Flarum\Admin\Content;
|
||||
|
||||
use Flarum\Extension\ExtensionManager;
|
||||
use Flarum\Frontend\Content\ContentInterface;
|
||||
use Flarum\Frontend\HtmlDocument;
|
||||
use Flarum\Frontend\Document;
|
||||
use Flarum\Group\Permission;
|
||||
use Flarum\Settings\Event\Deserializing;
|
||||
use Flarum\Settings\SettingsRepositoryInterface;
|
||||
@@ -21,7 +20,7 @@ use Illuminate\Contracts\Events\Dispatcher;
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
|
||||
class AdminPayload implements ContentInterface
|
||||
class AdminPayload
|
||||
{
|
||||
/**
|
||||
* @var SettingsRepositoryInterface
|
||||
@@ -52,7 +51,7 @@ class AdminPayload implements ContentInterface
|
||||
$this->events = $events;
|
||||
}
|
||||
|
||||
public function __invoke(HtmlDocument $document, Request $request)
|
||||
public function __invoke(Document $document, Request $request)
|
||||
{
|
||||
$settings = $this->settings->all();
|
||||
|
||||
|
Reference in New Issue
Block a user