|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: dsmrt |
|
5
|
|
|
* Date: 3/18/18 |
|
6
|
|
|
* Time: 9:45 PM |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace flipbox\keychain\controllers\cp; |
|
10
|
|
|
|
|
11
|
|
|
use craft\helpers\UrlHelper; |
|
12
|
|
|
use craft\web\Controller; |
|
13
|
|
|
use craft\base\Plugin; |
|
14
|
|
|
use flipbox\keychain\KeyChain; |
|
15
|
|
|
|
|
16
|
|
|
abstract class AbstractController extends Controller |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @return Plugin |
|
20
|
|
|
*/ |
|
21
|
|
|
abstract protected function getPlugin(); |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @return array |
|
25
|
|
|
*/ |
|
26
|
|
|
protected function getBaseVariables() |
|
27
|
|
|
{ |
|
28
|
|
|
$variables = [ |
|
29
|
|
|
'pluginHandle' => $this->getPlugin()->getUniqueId(), |
|
30
|
|
|
'title' => $this->getPlugin()->name . ' - ' . KeyChain::getInstance()->name, |
|
31
|
|
|
// Set the "Continue Editing" URL |
|
32
|
|
|
'continueEditingUrl' => $this->getBaseCpPath(), |
|
33
|
|
|
'baseActionPath' => $this->getBaseActionPath(), |
|
34
|
|
|
'baseCpPath' => $this->getBaseCpPath(), |
|
35
|
|
|
'actions' => [], |
|
36
|
|
|
]; |
|
37
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
if (! ($this->getPlugin() instanceof KeyChain)) { |
|
40
|
|
|
$variables['crumbs'][] = [ |
|
41
|
|
|
'url' => UrlHelper::cpUrl($this->getPlugin()->getUniqueId()), |
|
42
|
|
|
'label' => $this->getPlugin()->name, |
|
43
|
|
|
]; |
|
44
|
|
|
} |
|
45
|
|
|
$variables['crumbs'][] = [ |
|
46
|
|
|
'url' => UrlHelper::cpUrl($variables['baseCpPath']), |
|
47
|
|
|
'label' => 'KeyChain', |
|
48
|
|
|
]; |
|
49
|
|
|
return $variables; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @return string |
|
54
|
|
|
*/ |
|
55
|
|
|
protected function getBaseActionPath(): string |
|
56
|
|
|
{ |
|
57
|
|
|
return KeyChain::getInstance()->getUniqueId(); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @return string |
|
62
|
|
|
*/ |
|
63
|
|
|
protected function getBaseCpPath(): string |
|
64
|
|
|
{ |
|
65
|
|
|
if ($this->getPlugin() instanceof KeyChain) { |
|
66
|
|
|
return KeyChain::getInstance()->getUniqueId(); |
|
67
|
|
|
} |
|
68
|
|
|
return $this->getPlugin()->getUniqueId() . '/' . KeyChain::getInstance()->getUniqueId(); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @param array $variables |
|
73
|
|
|
* @return array |
|
74
|
|
|
*/ |
|
75
|
|
|
protected function beforeRender(array $variables = []) |
|
76
|
|
|
{ |
|
77
|
|
|
return $variables; |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|