forked from felixhahnweilheim/humhub-flex-theme
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Module.php
72 lines (61 loc) · 1.86 KB
/
Module.php
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
<?php
namespace humhub\modules\flexTheme;
use humhub\modules\flexTheme\models\ColorSettings;
use humhub\modules\flexTheme\helpers\FileHelper;
use humhub\modules\ui\view\helpers\ThemeHelper;
use humhub\libs\DynamicConfig;
use Yii;
use yii\helpers\Url;
class Module extends \humhub\components\Module
{
public $resourcesPath = 'resources';
public const FLEX_THEME_NAME = 'FlexTheme';
// Translatable Module Description
public function getDescription()
{
return Yii::t('FlexThemeModule.admin', 'Flexible Theme for HumHub');
}
// Link to configuration page
public function getConfigUrl()
{
return Url::to(['/flex-theme/config']);
}
// Module Activation
public function enable()
{
if (parent::enable()) {
$this->enableTheme();
return true;
}
return false;
}
private function enableTheme(): void
{
// Save special colors (lightened, darkened, faded colors), create theme files etc.
$model = new ColorSettings();
$model->save();
// see https://community.humhub.com/s/module-development/wiki/Theme+Modules
$theme = ThemeHelper::getThemeByName(self::FLEX_THEME_NAME);
if ($theme !== null) {
$theme->activate();
DynamicConfig::rewrite();
}
}
// Module Deactivation
public function disable(): void
{
$this->disableTheme();
parent::disable();
}
// see https://community.humhub.com/s/module-development/wiki/Theme+Modules
private function disableTheme(): void
{
foreach (ThemeHelper::getThemeTree(Yii::$app->view->theme) as $theme) {
if ($theme->name === self::FLEX_THEME_NAME) {
$theme = ThemeHelper::getThemeByName('HumHub');
$theme->activate();
break;
}
}
}
}