mirror of
https://github.com/flarum/core.git
synced 2025-07-25 18:51:40 +02: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:
@@ -11,12 +11,14 @@
|
|||||||
namespace Flarum\Admin\Actions;
|
namespace Flarum\Admin\Actions;
|
||||||
|
|
||||||
use Flarum\Support\ClientAction as BaseClientAction;
|
use Flarum\Support\ClientAction as BaseClientAction;
|
||||||
|
use Flarum\Support\ClientView;
|
||||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||||
use Flarum\Core\Groups\Permission;
|
use Flarum\Core\Groups\Permission;
|
||||||
use Flarum\Api\Client;
|
use Flarum\Api\Client;
|
||||||
use Flarum\Core\Settings\SettingsRepository;
|
use Flarum\Core\Settings\SettingsRepository;
|
||||||
use Flarum\Locale\LocaleManager;
|
use Flarum\Locale\LocaleManager;
|
||||||
use Flarum\Events\UnserializeConfig;
|
use Flarum\Events\UnserializeConfig;
|
||||||
|
use Flarum\Events\BuildAdminClientView;
|
||||||
|
|
||||||
class ClientAction extends BaseClientAction
|
class ClientAction extends BaseClientAction
|
||||||
{
|
{
|
||||||
@@ -42,6 +44,14 @@ class ClientAction extends BaseClientAction
|
|||||||
$this->layout = __DIR__.'/../../../views/admin.blade.php';
|
$this->layout = __DIR__.'/../../../views/admin.blade.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function fireEvent(ClientView $view, array &$keys)
|
||||||
|
{
|
||||||
|
event(new BuildAdminClientView($this, $view, $keys));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
34
framework/core/src/Events/BuildAdminClientView.php
Normal file
34
framework/core/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\ClientAction;
|
||||||
use Flarum\Support\ClientView;
|
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
|
* @var ClientAction
|
||||||
@@ -32,61 +30,20 @@ class BuildClientView
|
|||||||
*/
|
*/
|
||||||
public $keys;
|
public $keys;
|
||||||
|
|
||||||
/**
|
public function assets($files)
|
||||||
* @param ClientAction $action
|
|
||||||
* @param ClientView $view
|
|
||||||
* @param array $keys
|
|
||||||
*/
|
|
||||||
public function __construct($action, $view, &$keys)
|
|
||||||
{
|
{
|
||||||
$this->action = $action;
|
$this->view->getAssets()->addFiles((array) $files);
|
||||||
$this->view = $view;
|
|
||||||
$this->keys = &$keys;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function forumAssets($files)
|
public function bootstrapper($bootstrapper)
|
||||||
{
|
{
|
||||||
if ($this->action instanceof ForumClientAction) {
|
$this->view->addBootstrapper($bootstrapper);
|
||||||
$this->view->getAssets()->addFiles((array) $files);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function forumBootstrapper($bootstrapper)
|
public function translations(array $keys)
|
||||||
{
|
{
|
||||||
if ($this->action instanceof ForumClientAction) {
|
foreach ($keys as $key) {
|
||||||
$this->view->addBootstrapper($bootstrapper);
|
$this->keys[] = $key;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
34
framework/core/src/Events/BuildForumClientView.php
Normal file
34
framework/core/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;
|
namespace Flarum\Forum\Actions;
|
||||||
|
|
||||||
use Flarum\Support\ClientAction as BaseClientAction;
|
use Flarum\Support\ClientAction as BaseClientAction;
|
||||||
|
use Flarum\Support\ClientView;
|
||||||
use Flarum\Api\Client;
|
use Flarum\Api\Client;
|
||||||
use Flarum\Core\Settings\SettingsRepository;
|
use Flarum\Core\Settings\SettingsRepository;
|
||||||
use Flarum\Locale\LocaleManager;
|
use Flarum\Locale\LocaleManager;
|
||||||
|
use Flarum\Events\BuildForumClientView;
|
||||||
|
|
||||||
class ClientAction extends BaseClientAction
|
class ClientAction extends BaseClientAction
|
||||||
{
|
{
|
||||||
@@ -39,6 +41,14 @@ class ClientAction extends BaseClientAction
|
|||||||
$this->layout = __DIR__.'/../../../views/forum.blade.php';
|
$this->layout = __DIR__.'/../../../views/forum.blade.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function fireEvent(ClientView $view, array &$keys)
|
||||||
|
{
|
||||||
|
event(new BuildForumClientView($this, $view, $keys));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
|
@@ -17,7 +17,6 @@ use Flarum\Assets\LessCompiler;
|
|||||||
use Flarum\Core;
|
use Flarum\Core;
|
||||||
use Flarum\Core\Settings\SettingsRepository;
|
use Flarum\Core\Settings\SettingsRepository;
|
||||||
use Flarum\Core\Users\User;
|
use Flarum\Core\Users\User;
|
||||||
use Flarum\Events\BuildClientView;
|
|
||||||
use Flarum\Locale\JsCompiler as LocaleJsCompiler;
|
use Flarum\Locale\JsCompiler as LocaleJsCompiler;
|
||||||
use Flarum\Locale\LocaleManager;
|
use Flarum\Locale\LocaleManager;
|
||||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||||
@@ -122,7 +121,7 @@ abstract class ClientAction extends HtmlAction
|
|||||||
// compile only the ones we need.
|
// compile only the ones we need.
|
||||||
$keys = $this->translationKeys;
|
$keys = $this->translationKeys;
|
||||||
|
|
||||||
event(new BuildClientView($this, $view, $keys));
|
$this->fireEvent($view, $keys);
|
||||||
|
|
||||||
if ($localeCompiler) {
|
if ($localeCompiler) {
|
||||||
$translations = $this->locales->getTranslations($locale);
|
$translations = $this->locales->getTranslations($locale);
|
||||||
@@ -135,6 +134,13 @@ abstract class ClientAction extends HtmlAction
|
|||||||
return $view;
|
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
|
* Flush the client's assets so that they will be regenerated from scratch
|
||||||
* on the next render.
|
* on the next render.
|
||||||
|
Reference in New Issue
Block a user