mirror of
https://github.com/flarum/framework.git
synced 2025-01-19 07:42:48 +08:00
API: Split BuildClientView into two separate events
Much easier to work with. Extension stub hasn't been updated yet.
This commit is contained in:
parent
f255d318ef
commit
58eaf79a98
|
@ -11,12 +11,14 @@
|
|||
namespace Flarum\Admin\Actions;
|
||||
|
||||
use Flarum\Support\ClientAction as BaseClientAction;
|
||||
use Flarum\Support\ClientView;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use Flarum\Core\Groups\Permission;
|
||||
use Flarum\Api\Client;
|
||||
use Flarum\Core\Settings\SettingsRepository;
|
||||
use Flarum\Locale\LocaleManager;
|
||||
use Flarum\Events\UnserializeConfig;
|
||||
use Flarum\Events\BuildAdminClientView;
|
||||
|
||||
class ClientAction extends BaseClientAction
|
||||
{
|
||||
|
@ -42,6 +44,14 @@ class ClientAction extends BaseClientAction
|
|||
$this->layout = __DIR__.'/../../../views/admin.blade.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function fireEvent(ClientView $view, array &$keys)
|
||||
{
|
||||
event(new BuildAdminClientView($this, $view, $keys));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
34
src/Events/BuildAdminClientView.php
Normal file
34
src/Events/BuildAdminClientView.php
Normal file
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* (c) Toby Zerner <toby.zerner@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Events;
|
||||
|
||||
use Flarum\Support\ClientView;
|
||||
use Flarum\Admin\Actions\ClientAction;
|
||||
|
||||
class BuildAdminClientView extends BuildClientView
|
||||
{
|
||||
/**
|
||||
* @var ClientAction
|
||||
*/
|
||||
public $action;
|
||||
|
||||
/**
|
||||
* @param ClientAction $action
|
||||
* @param ClientView $view
|
||||
* @param array $keys
|
||||
*/
|
||||
public function __construct(ClientAction $action, ClientView $view, array &$keys)
|
||||
{
|
||||
$this->action = $action;
|
||||
$this->view = $view;
|
||||
$this->keys = &$keys;
|
||||
}
|
||||
}
|
|
@ -12,10 +12,8 @@ namespace Flarum\Events;
|
|||
|
||||
use Flarum\Support\ClientAction;
|
||||
use Flarum\Support\ClientView;
|
||||
use Flarum\Forum\Actions\ClientAction as ForumClientAction;
|
||||
use Flarum\Admin\Actions\ClientAction as AdminClientAction;
|
||||
|
||||
class BuildClientView
|
||||
abstract class BuildClientView
|
||||
{
|
||||
/**
|
||||
* @var ClientAction
|
||||
|
@ -32,61 +30,20 @@ class BuildClientView
|
|||
*/
|
||||
public $keys;
|
||||
|
||||
/**
|
||||
* @param ClientAction $action
|
||||
* @param ClientView $view
|
||||
* @param array $keys
|
||||
*/
|
||||
public function __construct($action, $view, &$keys)
|
||||
public function assets($files)
|
||||
{
|
||||
$this->action = $action;
|
||||
$this->view = $view;
|
||||
$this->keys = &$keys;
|
||||
$this->view->getAssets()->addFiles((array) $files);
|
||||
}
|
||||
|
||||
public function forumAssets($files)
|
||||
public function bootstrapper($bootstrapper)
|
||||
{
|
||||
if ($this->action instanceof ForumClientAction) {
|
||||
$this->view->getAssets()->addFiles((array) $files);
|
||||
}
|
||||
$this->view->addBootstrapper($bootstrapper);
|
||||
}
|
||||
|
||||
public function forumBootstrapper($bootstrapper)
|
||||
public function translations(array $keys)
|
||||
{
|
||||
if ($this->action instanceof ForumClientAction) {
|
||||
$this->view->addBootstrapper($bootstrapper);
|
||||
}
|
||||
}
|
||||
|
||||
public function forumTranslations(array $keys)
|
||||
{
|
||||
if ($this->action instanceof ForumClientAction) {
|
||||
foreach ($keys as $key) {
|
||||
$this->keys[] = $key;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function adminAssets($files)
|
||||
{
|
||||
if ($this->action instanceof AdminClientAction) {
|
||||
$this->view->getAssets()->addFiles((array) $files);
|
||||
}
|
||||
}
|
||||
|
||||
public function adminBootstrapper($bootstrapper)
|
||||
{
|
||||
if ($this->action instanceof AdminClientAction) {
|
||||
$this->view->addBootstrapper($bootstrapper);
|
||||
}
|
||||
}
|
||||
|
||||
public function adminTranslations(array $keys)
|
||||
{
|
||||
if ($this->action instanceof AdminClientAction) {
|
||||
foreach ($keys as $key) {
|
||||
$this->keys[] = $key;
|
||||
}
|
||||
foreach ($keys as $key) {
|
||||
$this->keys[] = $key;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
34
src/Events/BuildForumClientView.php
Normal file
34
src/Events/BuildForumClientView.php
Normal file
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* (c) Toby Zerner <toby.zerner@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Events;
|
||||
|
||||
use Flarum\Support\ClientView;
|
||||
use Flarum\Forum\Actions\ClientAction;
|
||||
|
||||
class BuildForumClientView extends BuildClientView
|
||||
{
|
||||
/**
|
||||
* @var ClientAction
|
||||
*/
|
||||
public $action;
|
||||
|
||||
/**
|
||||
* @param ClientAction $action
|
||||
* @param ClientView $view
|
||||
* @param array $keys
|
||||
*/
|
||||
public function __construct(ClientAction $action, ClientView $view, array &$keys)
|
||||
{
|
||||
$this->action = $action;
|
||||
$this->view = $view;
|
||||
$this->keys = &$keys;
|
||||
}
|
||||
}
|
|
@ -11,9 +11,11 @@
|
|||
namespace Flarum\Forum\Actions;
|
||||
|
||||
use Flarum\Support\ClientAction as BaseClientAction;
|
||||
use Flarum\Support\ClientView;
|
||||
use Flarum\Api\Client;
|
||||
use Flarum\Core\Settings\SettingsRepository;
|
||||
use Flarum\Locale\LocaleManager;
|
||||
use Flarum\Events\BuildForumClientView;
|
||||
|
||||
class ClientAction extends BaseClientAction
|
||||
{
|
||||
|
@ -39,6 +41,14 @@ class ClientAction extends BaseClientAction
|
|||
$this->layout = __DIR__.'/../../../views/forum.blade.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function fireEvent(ClientView $view, array &$keys)
|
||||
{
|
||||
event(new BuildForumClientView($this, $view, $keys));
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
|
|
|
@ -17,7 +17,6 @@ use Flarum\Assets\LessCompiler;
|
|||
use Flarum\Core;
|
||||
use Flarum\Core\Settings\SettingsRepository;
|
||||
use Flarum\Core\Users\User;
|
||||
use Flarum\Events\BuildClientView;
|
||||
use Flarum\Locale\JsCompiler as LocaleJsCompiler;
|
||||
use Flarum\Locale\LocaleManager;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
|
@ -122,7 +121,7 @@ abstract class ClientAction extends HtmlAction
|
|||
// compile only the ones we need.
|
||||
$keys = $this->translationKeys;
|
||||
|
||||
event(new BuildClientView($this, $view, $keys));
|
||||
$this->fireEvent($view, $keys);
|
||||
|
||||
if ($localeCompiler) {
|
||||
$translations = $this->locales->getTranslations($locale);
|
||||
|
@ -135,6 +134,13 @@ abstract class ClientAction extends HtmlAction
|
|||
return $view;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ClientView $view
|
||||
* @param array &$keys
|
||||
* @return void
|
||||
*/
|
||||
abstract protected function fireEvent(ClientView $view, array &$keys);
|
||||
|
||||
/**
|
||||
* Flush the client's assets so that they will be regenerated from scratch
|
||||
* on the next render.
|
||||
|
|
Loading…
Reference in New Issue
Block a user