-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathEvents.php
More file actions
80 lines (66 loc) · 2.25 KB
/
Events.php
File metadata and controls
80 lines (66 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
/**
* Clean Theme
* @link https://github.com/cuzy-app/clean-theme
* @license https://github.com/cuzy-app/clean-theme/blob/master/docs/LICENCE.md
* @author [Marc FARRE](https://marc.fun) for [CUZY.APP](https://www.cuzy.app)
*/
namespace humhub\modules\cleanTheme;
use humhub\assets\TopNavigationAsset;
use humhub\components\console\Application;
use humhub\components\View;
use humhub\modules\cleanTheme\assets\CleanThemeAsset;
use humhub\modules\cleanTheme\assets\CleanThemeTopNavigationAsset;
use humhub\modules\cleanTheme\commands\DeveloperController;
use Yii;
class Events
{
public static function onConsoleApplicationInit($event)
{
/** @var Application $application */
$application = $event->sender;
$application->controllerMap['clean-theme'] = DeveloperController::class;
}
public static function onViewBeforeRender($event)
{
/** @var View $view */
$view = $event->sender;
$module = static::getModuleIfThemeActive();
if (!$module) {
return;
}
// Unregister the core TopNavigationAsset to prevent conflicts with the Clean Theme
unset($view->assetBundles[TopNavigationAsset::class]);
}
public static function onViewBeginBody($event)
{
if (Yii::$app->request->isAjax) {
return;
}
$module = static::getModuleIfThemeActive();
if (!$module) {
return;
}
/** @var View $view */
$view = $event->sender;
// Register the Clean Theme Assets instead
CleanThemeAsset::register($view);
CleanThemeTopNavigationAsset::register($view);
$view->registerJsConfig('cleanTheme.topNavigation', [
'hideTopMenuOnScrollDown' => $module?->configuration->hideTopMenuOnScrollDown ?? false,
'hideBottomMenuOnScrollDown' => $module?->configuration->hideBottomMenuOnScrollDown ?? false,
]);
}
protected static function getModuleIfThemeActive(): ?Module
{
if (!Module::isThemeBasedActive()) {
return null;
}
/** @var Module $module */
$module = Yii::$app->getModule('clean-theme');
if (!$module?->isEnabled) {
return null;
}
return $module;
}
}