mirror of
https://github.com/flarum/core.git
synced 2025-08-01 14:10:37 +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:
@@ -4,6 +4,7 @@
|
||||
// classes in the src directory to be autoloaded.
|
||||
require __DIR__.'/vendor/autoload.php';
|
||||
|
||||
// Register our service provider with the Flarum application. In here we can
|
||||
// register bindings and execute code when the application boots.
|
||||
return $this->app->register('{{namespace}}\{{classPrefix}}ServiceProvider');
|
||||
// Return the name of our Extension class. Flarum will register it as a service
|
||||
// provider, allowing it to register bindings and execute code when the
|
||||
// application boots.
|
||||
return '{{namespace}}\Extension';
|
||||
|
8
stubs/extension/js/bootstrap.js
vendored
8
stubs/extension/js/bootstrap.js
vendored
@@ -1,8 +0,0 @@
|
||||
import { extend, override } from 'flarum/extension-utils';
|
||||
import app from 'flarum/app';
|
||||
|
||||
app.initializers.add('{{name}}', function() {
|
||||
|
||||
// @todo
|
||||
|
||||
});
|
4
stubs/extension/js/src/main.js
Normal file
4
stubs/extension/js/src/main.js
Normal file
@@ -0,0 +1,4 @@
|
||||
import { extend } from 'flarum/extend';
|
||||
import app from 'flarum/app';
|
||||
|
||||
// TODO
|
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