mirror of
https://github.com/flarum/core.git
synced 2025-05-05 06:57:55 +02:00
Admin: Set up all event listeners in one place
See discussion in #1273.
This commit is contained in:
parent
b760d113d2
commit
63be95fb8a
@ -76,11 +76,7 @@ class AdminServiceProvider extends AbstractServiceProvider
|
|||||||
|
|
||||||
$this->loadViewsFrom(__DIR__.'/../../views', 'flarum.admin');
|
$this->loadViewsFrom(__DIR__.'/../../views', 'flarum.admin');
|
||||||
|
|
||||||
$this->flushWebAppAssetsWhenThemeChanged();
|
$this->registerListeners();
|
||||||
|
|
||||||
$this->flushWebAppAssetsWhenExtensionsChanged();
|
|
||||||
|
|
||||||
$this->checkCustomLessFormat();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -96,21 +92,23 @@ class AdminServiceProvider extends AbstractServiceProvider
|
|||||||
$callback($routes, $factory);
|
$callback($routes, $factory);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function flushWebAppAssetsWhenThemeChanged()
|
protected function registerListeners()
|
||||||
{
|
{
|
||||||
$this->app->make('events')->listen(Saved::class, function (Saved $event) {
|
$dispatcher = $this->app->make('events');
|
||||||
|
|
||||||
|
// Flush web app assets when the theme is changed
|
||||||
|
$dispatcher->listen(Saved::class, function (Saved $event) {
|
||||||
if (preg_match('/^theme_|^custom_less$/i', $event->key)) {
|
if (preg_match('/^theme_|^custom_less$/i', $event->key)) {
|
||||||
$this->getWebAppAssets()->flushCss();
|
$this->getWebAppAssets()->flushCss();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
protected function flushWebAppAssetsWhenExtensionsChanged()
|
// Flush web app assets when extensions are changed
|
||||||
{
|
$dispatcher->listen(Enabled::class, [$this, 'flushWebAppAssets']);
|
||||||
$events = $this->app->make('events');
|
$dispatcher->listen(Disabled::class, [$this, 'flushWebAppAssets']);
|
||||||
|
|
||||||
$events->listen(Enabled::class, [$this, 'flushWebAppAssets']);
|
// Check the format of custom LESS code
|
||||||
$events->listen(Disabled::class, [$this, 'flushWebAppAssets']);
|
$dispatcher->subscribe(CheckCustomLessFormat::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function flushWebAppAssets()
|
public function flushWebAppAssets()
|
||||||
@ -125,11 +123,4 @@ class AdminServiceProvider extends AbstractServiceProvider
|
|||||||
{
|
{
|
||||||
return $this->app->make(Frontend::class)->getAssets();
|
return $this->app->make(Frontend::class)->getAssets();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function checkCustomLessFormat()
|
|
||||||
{
|
|
||||||
$events = $this->app->make('events');
|
|
||||||
|
|
||||||
$events->subscribe(CheckCustomLessFormat::class);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user