1
0
mirror of https://github.com/flarum/core.git synced 2025-02-25 03:33:42 +01:00

Update extension skeleton

Closes #743.
This commit is contained in:
Franz Liedke 2016-01-20 22:13:55 +01:00
parent c99c83435b
commit e0790de2e5
5 changed files with 42 additions and 91 deletions

View File

@ -1,10 +1,14 @@
<?php
// Require the extension's composer autoload file. This will enable all of our
// classes in the src directory to be autoloaded.
require __DIR__.'/vendor/autoload.php';
use Illuminate\Contracts\Events\Dispatcher;
use {{namespace}}\Listener;
// 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';
// Return a function that registers the extension with Flarum. This is
// the place to listen to events, register bindings with the container
// and execute code when the application boots.
//
// Any typehinted argument of this function is automatically resolved
// by the IoC container.
return function (Dispatcher $events) {
$events->subscribe(Listener\AddClientAssets::class);
};

View File

@ -1,28 +0,0 @@
{{name}}:
##
# UNIQUE KEYS - The following keys are used in only one location each.
##
# Translations in this namespace are used by the admin interface.
admin:
# These keys are provided as examples. Delete them before using this template!
sample_location:
sample_text: "Hello, world!"
# Translations in this namespace are used by the forum user interface.
forum:
# Translations in this namespace are used by the forum and admin interfaces.
lib:
##
# REUSED TRANSLATIONS - These keys should not be used directly in code!
##
# Translations in this namespace are referenced by two or more unique keys.
ref:

View File

@ -1,12 +0,0 @@
<?php namespace {{namespace}};
use Flarum\Support\Extension as BaseExtension;
use Illuminate\Events\Dispatcher;
class Extension extends BaseExtension
{
public function listen(Dispatcher $events)
{
$events->subscribe('{{namespace}}\Listeners\AddClientAssets');
}
}

View File

@ -0,0 +1,31 @@
<?php namespace {{namespace}}\Listener;
use Flarum\Event\ConfigureClientView;
use Illuminate\Contracts\Events\Dispatcher;
class AddClientAssets
{
public function subscribe(Dispatcher $events)
{
$events->listen(ConfigureClientView::class, [$this, 'addAssets']);
}
public function addAssets(ConfigureClientView $event)
{
if ($event->isForum()) {
$event->addAssets([
__DIR__.'/../../js/forum/dist/extension.js',
__DIR__.'/../../less/forum/extension.less',
]);
$event->addBootstrapper('{{name}}/main');
}
if ($event->isAdmin()) {
$event->addAssets([
__DIR__.'/../../js/admin/dist/extension.js',
__DIR__.'/../../less/admin/extension.less',
]);
$event->addBootstrapper('{{name}}/main');
}
}
}

View File

@ -1,44 +0,0 @@
<?php namespace {{namespace}}\Listeners;
use Flarum\Event\ConfigureLocales;
use Flarum\Event\ConfigureClientView;
use Illuminate\Contracts\Events\Dispatcher;
class AddClientAssets
{
public function subscribe(Dispatcher $events)
{
$events->listen(ConfigureLocales::class, [$this, 'addLocale']);
$events->listen(ConfigureClientView::class, [$this, 'addAssets']);
}
public function addLocale(ConfigureLocales $event)
{
$event->addTranslations('en', __DIR__.'/../../locale/en.yml');
}
public function addAssets(ConfigureClientView $event)
{
$event->forumAssets([
__DIR__.'/../../js/forum/dist/extension.js',
__DIR__.'/../../less/forum/extension.less'
]);
$event->forumBootstrapper('{{name}}/main');
$event->forumTranslations([
// '{{name}}.hello_world'
]);
$event->adminAssets([
__DIR__.'/../../js/admin/dist/extension.js',
__DIR__.'/../../less/admin/extension.less'
]);
$event->adminBootstrapper('{{name}}/main');
$event->adminTranslations([
// '{{name}}.hello_world'
]);
}
}