forked from dmstr/yii2-pages-module
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModule.php
83 lines (75 loc) · 2.54 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
73
74
75
76
77
78
79
80
81
82
83
<?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 yii\filters\AccessControl;
/**
* Class Module
* @package dmstr\modules\pages
* @author Christopher Stebe <[email protected]>
*/
class Module extends \yii\base\Module
{
/**
* @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 = [];
public $pagesWithChildrenHasUrl = false;
public $availableRoutes = [
'/pages/default/page' => '/pages/default/page',
'/site/index' => '/site/index',
];
public $availableViews = [
'@vendor/dmstr/yii2-widgets-module/example-views/default.php' => 'Default',
'@vendor/dmstr/yii2-widgets-module/example-views/column1.php' => 'One Column (with container)'
];
/**
* Restrict access permissions to admin user and users with auth-item 'module-controller'
* @inheritdoc
*/
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'allow' => true,
'matchCallback' => function () {
if ($this->roles) {
foreach ($this->roles as $role) {
if (\Yii::$app->user->can($role)) {
return true;
}
}
return (\Yii::$app->user->identity && \Yii::$app->user->identity->isAdmin);
}
return true;
},
]
]
]
];
}
public function getLocalizedRootNode()
{
$localizedRoot = 'root_' . \Yii::$app->language;
\Yii::trace('localizedRoot: ' . $localizedRoot, __METHOD__);
$page = Tree::findOne(
[
Tree::ATTR_NAME_ID => $localizedRoot,
Tree::ATTR_ACTIVE => Tree::ACTIVE,
Tree::ATTR_VISIBLE => Tree::VISIBLE
]
);
return $page;
}
}