Repository navigation
Expand file tree
/
Copy pathModule.php
More file actions
117 lines (102 loc) · 3.49 KB
/
Copy pathModule.php
File metadata and controls
117 lines (102 loc) · 3.49 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
/**
* @link http://www.diemeisterei.de/
*
* @copyright Copyright (c) 2015 diemeisterei GmbH, Stuttgart
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace dmstr\modules\pages;
use dmstr\modules\pages\models\Tree;
use dmstr\web\traits\AccessBehaviorTrait;
use yii\console\Application;
/**
* Class Module.
*
* @author Christopher Stebe <c.stebe@herzogkommunikation.de>
*
*/
class Module extends \yii\base\Module
{
use AccessBehaviorTrait;
/**
* The name of this module
*/
const NAME = 'pages';
/**
* @var array the list of rights that are allowed to access this module.
* If you modify, you also need to enable authManager.
* http://www.yiiframework.com/doc-2.0/guide-security-authorization.html
*/
public $roles = [];
/**
* alias for the pages/default/page action
*
* @var string
*/
public $defaultPageLayout = '@app/views/layouts/main';
/**
* @var array
*/
public $availableRoutes = [];
/**
* @var array
*/
public $availableViews = [];
/**
* Whether access_domain should be used as constraint in default/page action select
*
* @var bool
*/
public $pageCheckAccessDomain = false;
/**
* Whether to search fallbackPage according to domain_id
*
* see: \dmstr\modules\pages\controllers\DefaultController::resolveFallbackPage
* @var bool
*/
public $pageUseFallbackPage = true;
/**
* @inheritdoc
*/
public function init()
{
parent::init();
// add routes from settings module
if (self::checkSettingsInstalled()) {
$routes = explode("\n", (string)\Yii::$app->settings->get('pages.availableRoutes'));
foreach ($routes as $route) {
$routeEntry = trim($route);
$this->availableRoutes[$routeEntry] = $routeEntry;
}
$views = explode("\n", (string)\Yii::$app->settings->get('pages.availableViews'));
foreach ($views as $view) {
// use custom name if appended after a semicolon (;)
$viewEntry = explode(';', trim($view));
$this->availableViews[$viewEntry[0]] = $viewEntry[1] ?? $viewEntry[0];
}
if (!\Yii::$app instanceof Application && \Yii::$app->has('user') && \Yii::$app->user->can(Tree::GLOBAL_ACCESS_PERMISSION)) {
$globalRoutes = explode("\n", (string)\Yii::$app->settings->get('pages.availableGlobalRoutes'));
foreach ($globalRoutes as $globalRoute) {
$globalRouteEntry = trim($globalRoute);
$this->availableRoutes[$globalRouteEntry] = $globalRouteEntry;
}
$globalViews = explode("\n", (string)\Yii::$app->settings->get('pages.availableGlobalViews'));
foreach ($globalViews as $globalView) {
// use custom name if appended after a semicolon (;)
$globalViewEntry = explode(';', trim($globalView));
$this->availableViews[$globalViewEntry[0]] = $globalViewEntry[1] ?? $globalViewEntry[0];
}
}
}
}
/**
* Check for "pheme/yii2-settings" component and module
* @return bool
*/
public static function checkSettingsInstalled()
{
return \Yii::$app->hasModule('settings') && \Yii::$app->has('settings');
}
}