-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathModule.php
More file actions
101 lines (87 loc) · 2.37 KB
/
Module.php
File metadata and controls
101 lines (87 loc) · 2.37 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
/**
* Transition Movement
* @link https://github.com/transitionnetwork/Humhub-Transition
* @license https://github.com/transitionnetwork/Humhub-Transition/blob/main/docs/LICENCE.md
* @author [Marc FARRE](https://marc.fun) for [Transition Movement](https://transitionnetwork.org/)
*/
namespace humhub\modules\transition;
use humhub\helpers\ThemeHelper;
use humhub\modules\content\components\ContentContainerModule;
use humhub\modules\content\components\ContentContainerModuleManager;
use humhub\modules\transition\jobs\SyncAllSpaceHosts;
use humhub\modules\user\models\User;
use Yii;
class Module extends ContentContainerModule
{
public const THEME_NAME = 'transition';
/**
* @var string defines the icon
*/
public $icon = 'eye';
/**
* @var int Group ID for the "Space hosts" group (for spaces' administrators and moderators)
*/
public $spaceHostsGroupId;
public function getName()
{
return 'Transition Movement';
}
/**
* @inheritdoc
*/
public function getContentContainerTypes()
{
return [User::class];
}
/**
* @inheritdoc
*/
public function disable()
{
$this->disableTheme();
parent::disable();
}
/**
* @inheritdoc
*/
public function enable()
{
if (parent::enable() !== false) {
$this->enableTheme();
ContentContainerModuleManager::setDefaultState(User::class, 'transition', 1);
Yii::$app->queue->push(new SyncAllSpaceHosts());
return true;
}
return false;
}
/**
* @return void
*/
private function enableTheme()
{
// Check if already active
foreach (ThemeHelper::getThemeTree(Yii::$app->view->theme) as $theme) {
if ($theme->name === self::THEME_NAME) {
return;
}
}
$theme = ThemeHelper::getThemeByName(self::THEME_NAME);
if ($theme !== null) {
$theme->activate();
}
}
/**
* @return void
*/
private function disableTheme()
{
foreach (ThemeHelper::getThemeTree(Yii::$app->view->theme) as $theme) {
if ($theme->name === self::THEME_NAME) {
$ceTheme = ThemeHelper::getThemeByName('HumHub');
$ceTheme->activate();
break;
}
}
}
}