mirror of
https://github.com/flarum/core.git
synced 2025-10-09 22:16:51 +02:00
Rework extension bootstrapping
System JS modules don't execute when they're registered, so we need to import them explicitly. While we're at it, we may as well make the locale bootstrapper a module too.
This commit is contained in:
27
stubs/extension/src/Extension.php
Normal file
27
stubs/extension/src/Extension.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php namespace {{namespace}};
|
||||
|
||||
use Flarum\Support\Extension;
|
||||
use Illuminate\Events\Dispatcher;
|
||||
|
||||
class Extension extends BaseExtension
|
||||
{
|
||||
/**
|
||||
* Bootstrap the application events.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot(Dispatcher $events)
|
||||
{
|
||||
$events->subscribe('{{namespace}}\Listeners\AddClientAssets');
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
33
stubs/extension/src/Listeners/AddClientAssets.php
Executable file
33
stubs/extension/src/Listeners/AddClientAssets.php
Executable file
@@ -0,0 +1,33 @@
|
||||
<?php namespace {{namespace}}\Listeners;
|
||||
|
||||
use Flarum\Events\RegisterLocales;
|
||||
use Flarum\Events\BuildClientView;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
|
||||
class AddClientAssets
|
||||
{
|
||||
public function subscribe(Dispatcher $events)
|
||||
{
|
||||
$events->listen(RegisterLocales::class, __CLASS__.'@addLocale');
|
||||
$events->listen(BuildClientView::class, __CLASS__.'@addAssets');
|
||||
}
|
||||
|
||||
public function addLocale(RegisterLocales $event)
|
||||
{
|
||||
$event->addTranslations('en', __DIR__.'/../../locale/en.yml');
|
||||
}
|
||||
|
||||
public function addAssets(BuildClientView $event)
|
||||
{
|
||||
$event->forumAssets([
|
||||
__DIR__.'/../../js/dist/extension.js',
|
||||
__DIR__.'/../../less/extension.less'
|
||||
]);
|
||||
|
||||
$event->forumBootstrapper('{{name}}/main');
|
||||
|
||||
$event->forumTranslations([
|
||||
// '{{name}}.hello_world'
|
||||
]);
|
||||
}
|
||||
}
|
@@ -1,39 +0,0 @@
|
||||
<?php namespace {{namespace}};
|
||||
|
||||
use Flarum\Support\ServiceProvider;
|
||||
use Flarum\Extend;
|
||||
|
||||
class {{classPrefix}}ServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Bootstrap the application events.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$this->extend([
|
||||
(new Extend\Locale('en'))->translations(__DIR__.'/../locale/en.yml'),
|
||||
|
||||
(new Extend\ForumClient())
|
||||
->assets([
|
||||
__DIR__.'/../js/dist/extension.js',
|
||||
__DIR__.'/../less/extension.less'
|
||||
])
|
||||
->translations([
|
||||
// Add the keys of translations you would like to be available
|
||||
// for use by the JS client application.
|
||||
])
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user