Completed
Push — develop ( 856b14...45ab37 )
by Nate
17:44
created

TokensController::tokenVariables()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 0
cts 11
cp 0
rs 9.7998
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 2
1
<?php
2
3
namespace flipbox\patron\cp\controllers\view\providers;
4
5
use Craft;
6
use craft\helpers\UrlHelper;
7
use flipbox\craft\assets\card\Card;
8
use flipbox\craft\assets\circleicon\CircleIcon;
9
use flipbox\ember\web\assets\rowinfomodal\RowInfoModal;
10
use flipbox\patron\helpers\ProviderHelper as ProviderHelper;
11
use flipbox\patron\Patron;
12
use flipbox\patron\records\Provider;
13
use flipbox\patron\records\ProviderInstance;
14
use flipbox\patron\services\ManageProviders as ProviderService;
15
use flipbox\patron\web\assets\providerswitcher\ProvidersAsset;
16
17
class TokensController extends AbstractViewController
18
{
19
    /**
20
     * The index view template path
21
     */
22
    const TEMPLATE_INDEX = AbstractViewController::TEMPLATE_BASE . '/tokens';
23
24
    /**
25
     * The upsert view template path
26
     */
27
    const TEMPLATE_INSERT = self::TEMPLATE_INDEX . '/index';
28
29
    /**
30
     * @param null $identifier
31
     * @return \yii\web\Response
32
     * @throws \flipbox\ember\exceptions\NotFoundException
33
     * @throws \yii\base\InvalidConfigException
34
     */
35
    public function actionIndex($identifier = null)
36
    {
37
        Craft::$app->getView()->registerAssetBundle(CircleIcon::class);
38
        Craft::$app->getView()->registerAssetBundle(RowInfoModal::class);
39
40
        // Empty variables for template
41
        $variables = [];
42
43
        $provider = Patron::getInstance()->manageProviders()->getByCondition([
44
            'id' => $identifier,
45
            'environment' => null,
46
            'enabled' => null
47
        ]);
48
49
        // Template variables
50
        $this->tokenVariables($variables, $provider);
51
52
        $variables['provider'] = $provider;
53
54
        // Tabs
55
        $variables['tabs'] = $this->getTabs($provider);
56
        $variables['selectedTab'] = 'tokens';
57
58
        return $this->renderTemplate(static::TEMPLATE_INDEX, $variables);
59
    }
60
61
    /*******************************************
62
     * PATHS
63
     *******************************************/
64
65
    /**
66
     * @inheritdoc
67
     */
68
    protected function getBaseCpPath(): string
69
    {
70
        return parent::getBaseCpPath() . '/' . Craft::$app->getRequest()->getSegment(3);
71
    }
72
73
    /**
74
     * @inheritdoc
75
     */
76
    protected function getBaseActionPath(): string
77
    {
78
        return parent::getBaseActionPath() . '/tokens';
79
    }
80
81
82
    /*******************************************
83
     * VARIABLES
84
     *******************************************/
85
86
    /**
87
     * @param array $variables
88
     * @param Provider $provider
89
     */
90
    protected function tokenVariables(array &$variables, Provider $provider)
91
    {
92
        $this->updateVariables($variables, $provider);
93
94
        $variables['title'] .= ' ' . Craft::t('patron', "Tokens");
95
96
        // Breadcrumbs
97
        $variables['crumbs'][] = [
98
            'label' => Craft::t('patron', "Tokens"),
99
            'url' => UrlHelper::url(
100
                $variables['baseCpPath'] . '/tokens'
101
            )
102
        ];
103
    }
104
}
105