Completed
Push — master ( 7f45a1...6afdf1 )
by Andrey
01:18
created

AdminController::behaviors()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 22
rs 9.568
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Itstructure\AdminModule\controllers;
4
5
use Yii;
6
use yii\web\Controller;
7
use Itstructure\AdminModule\Module;
8
use yii\filters\{VerbFilter, AccessControl};
9
10
/**
11
 * Class AdminController
12
 * Default controller for the `admin` module.
13
 *
14
 * @property Module $module
15
 * @property string $urlPrefix Url prefix for redirect and view links.
16
 * @property string $urlPrefixNeighbor Url prefix for redirect and view links of neighbor entity.
17
 *
18
 * @package Itstructure\AdminModule\controllers
19
 *
20
 * @author Andrey Girnik <[email protected]>
21
 */
22
class AdminController extends Controller
23
{
24
    /**
25
     * Url prefix for redirect and view links.
26
     *
27
     * @var string
28
     */
29
    protected $urlPrefix = '';
30
31
    /**
32
     * Url prefix for redirect and view links of neighbor entity.
33
     *
34
     * @var string
35
     */
36
    protected $urlPrefixNeighbor = '';
37
38
    /**
39
     * Initialize.
40
     *
41
     * @return void
42
     */
43
    public function init()
44
    {
45
        $this->view->params['user'] = Yii::$app->user->identity;
46
    }
47
48
    /**
49
     * @param \yii\base\Action $action
50
     *
51
     * @return bool
52
     */
53
    public function beforeAction($action)
54
    {
55
        $this->view->params['urlPrefix']         = $this->urlPrefix;
56
        $this->view->params['urlPrefixNeighbor'] = $this->urlPrefixNeighbor;
57
58
        return parent::beforeAction($action);
59
    }
60
61
    /**
62
     * @inheritdoc
63
     */
64
    public function behaviors()
65
    {
66
        return [
67
            'access' => [
68
                'class' => AccessControl::class,
69
                'rules' => [
70
                    [
71
                        'allow' => true,
72
                        'roles' => $this->module->accessRoles,
73
                    ],
74
                ],
75
            ],
76
            'verbs' => [
77
                'class' => VerbFilter::class,
78
                'actions' => [
79
                    'delete' => [
80
                        'POST',
81
                    ],
82
                ],
83
            ],
84
        ];
85
    }
86
87
    /**
88
     * Give ability of configure view to the module class.
89
     *
90
     * @return \yii\base\View|\yii\web\View
91
     */
92
    public function getView()
93
    {
94
        if (method_exists($this->module, 'getView')) {
95
            return $this->module->getView();
96
        }
97
98
        return parent::getView();
99
    }
100
}
101