Cp::init()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1.008

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 8
cts 10
cp 0.8
rs 9.7998
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1.008
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://flipboxfactory.com/software/organization/license
6
 * @link       https://www.flipboxfactory.com/software/organization/
7
 */
8
9
namespace flipbox\organizations\cp;
10
11
use Craft;
12
use craft\events\RegisterTemplateRootsEvent;
13
use craft\web\View;
14
use flipbox\organizations\Organizations;
15
use yii\base\Event;
16
use yii\base\Module as BaseModule;
17
use yii\web\NotFoundHttpException;
18
19
/**
20
 * @author Flipbox Factory <[email protected]>
21
 * @since 1.0.0
22
 *
23
 * @property Organizations $module
24
 */
25
class Cp extends BaseModule
26
{
27
    /**
28
     * @inheritdoc
29
     */
30 3
    public function init()
31
    {
32 3
        parent::init();
33
34
        // Base template directory
35 3
        Event::on(
36 3
            View::class,
37 3
            View::EVENT_REGISTER_CP_TEMPLATE_ROOTS,
38 1
            function (RegisterTemplateRootsEvent $e) {
39
                $e->roots['nested-element-index'] = Craft::$app->getPath()->getVendorPath() .
40
                    '/flipboxfactory/craft-elements-nested-index/src/templates';
41 3
            }
42
        );
43 3
    }
44
45
    /**
46
     * @inheritdoc
47
     */
48
    public function beforeAction($action)
49
    {
50
        if (!Craft::$app->request->getIsCpRequest()) {
51
            /** @noinspection PhpUnhandledExceptionInspection */
52
            throw new NotFoundHttpException();
53
        }
54
55
        return parent::beforeAction($action);
56
    }
57
}
58