mirror of
https://github.com/flarum/framework.git
synced 2025-01-19 05:52:49 +08:00
Flush the embed client assets when settings are changed
This commit is contained in:
parent
f199620df8
commit
f6830c6ab6
|
@ -14,4 +14,5 @@ use Illuminate\Contracts\Events\Dispatcher;
|
|||
|
||||
return function (Dispatcher $events) {
|
||||
$events->subscribe(Listener\AddEmbedRoute::class);
|
||||
};
|
||||
$events->subscribe(Listener\FlushEmbedAssetsWhenSettingsAreChanged::class);
|
||||
};
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
<?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\Embed\Listener;
|
||||
|
||||
use Flarum\Embed\DiscussionController;
|
||||
use Flarum\Event\ExtensionWasDisabled;
|
||||
use Flarum\Event\ExtensionWasEnabled;
|
||||
use Flarum\Event\SettingWasSet;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
|
||||
class FlushEmbedAssetsWhenSettingsAreChanged
|
||||
{
|
||||
/**
|
||||
* @var DiscussionController
|
||||
*/
|
||||
protected $controller;
|
||||
|
||||
/**
|
||||
* @param DiscussionController $controller
|
||||
*/
|
||||
public function __construct(DiscussionController $controller)
|
||||
{
|
||||
$this->controller = $controller;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Dispatcher $events
|
||||
*/
|
||||
public function subscribe(Dispatcher $events)
|
||||
{
|
||||
$events->listen(SettingWasSet::class, [$this, 'flushCss']);
|
||||
$events->listen(ExtensionWasEnabled::class, [$this, 'flushAssets']);
|
||||
$events->listen(ExtensionWasDisabled::class, [$this, 'flushAssets']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SettingWasSet $event
|
||||
*/
|
||||
public function flushCss(SettingWasSet $event)
|
||||
{
|
||||
if (preg_match('/^theme_|^custom_less$/i', $event->key)) {
|
||||
$this->controller->flushCss();
|
||||
}
|
||||
}
|
||||
|
||||
public function flushAssets()
|
||||
{
|
||||
$this->controller->flushAssets();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user