AbstractViewController   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 101
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 4
dl 0
loc 101
ccs 0
cts 40
cp 0
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getBaseActionPath() 0 4 1
A getBaseCpPath() 0 4 1
A getBaseContinueEditingUrl() 0 4 1
A baseVariables() 0 36 2
A insertVariables() 0 17 1
1
<?php
2
3
namespace flipbox\patron\cp\controllers\view;
4
5
use Craft;
6
use craft\helpers\UrlHelper;
7
use craft\web\Controller;
8
use flipbox\patron\cp\Cp;
9
use flipbox\patron\Patron;
10
11
/**
12
 * @property Cp $module
13
 */
14
abstract class AbstractViewController extends Controller
15
{
16
    /**
17
     * The index view template path
18
     */
19
    const TEMPLATE_BASE = 'patron/_cp';
20
21
    /*******************************************
22
     * VARIABLES
23
     *******************************************/
24
25
    /**
26
     * @return string
27
     */
28
    protected function getBaseActionPath(): string
29
    {
30
        return Patron::getInstance()->getUniqueId() . '/cp';
31
    }
32
33
    /**
34
     * @return string
35
     */
36
    protected function getBaseCpPath(): string
37
    {
38
        return Patron::getInstance()->getUniqueId();
39
    }
40
41
    /**
42
     * @param string $endpoint
43
     * @return string
44
     */
45
    protected function getBaseContinueEditingUrl(string $endpoint = ''): string
46
    {
47
        return $this->getBaseCpPath() . $endpoint;
48
    }
49
50
    /*******************************************
51
     * VARIABLES
52
     *******************************************/
53
54
    /**
55
     * @inheritdoc
56
     */
57
    protected function baseVariables(array &$variables = [])
58
    {
59
60
        /** @var Patron $module */
61
        $module = Patron::getInstance();
62
63
        // Patron settings
64
        $variables['settings'] = $module->getSettings();
65
66
        // Page title
67
        $variables['title'] = Craft::t('patron', "Patron");
68
69
        // Selected tab
70
        $variables['selectedTab'] = '';
71
72
        // Path to controller actions
73
        $variables['baseActionPath'] = $this->getBaseActionPath();
74
75
        // Path to CP
76
        $variables['baseCpPath'] = $this->getBaseCpPath();
77
78
        // Set the "Continue Editing" URL
79
        $variables['continueEditingUrl'] = $this->getBaseContinueEditingUrl();
80
81
        // Select our sub-nav
82
        if (!$activeSubNav = Craft::$app->getRequest()->getSegment(2)) {
83
            $activeSubNav = 'providers';
84
        }
85
        $variables['selectedSubnavItem'] = 'patron.' . $activeSubNav;
86
87
        // Breadcrumbs
88
        $variables['crumbs'][] = [
89
            'label' => $variables['title'],
90
            'url' => UrlHelper::url(Patron::getInstance()->getUniqueId())
91
        ];
92
    }
93
94
    /**
95
     * @param array $variables
96
     */
97
    protected function insertVariables(array &$variables)
98
    {
99
        // apply base view variables
100
        $this->baseVariables($variables);
101
102
        // Set the "Continue Editing" URL
103
        $variables['continueEditingUrl'] = $this->getBaseContinueEditingUrl('/{id}');
104
105
        // Append title
106
        $variables['title'] .= ' - ' . Craft::t('patron', 'New');
107
108
        // Breadcrumbs
109
        $variables['crumbs'][] = [
110
            'label' => Craft::t('patron', 'New'),
111
            'url' => UrlHelper::url($variables['baseCpPath'] . '/new')
112
        ];
113
    }
114
}
115