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\controllers\view; |
10
|
|
|
|
11
|
|
|
use Craft; |
12
|
|
|
use craft\web\Controller; |
13
|
|
|
use flipbox\craft\ember\helpers\UrlHelper; |
14
|
|
|
use flipbox\organizations\cp\Cp as CpModule; |
15
|
|
|
use flipbox\organizations\Organizations as OrganizationPlugin; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @author Flipbox Factory <[email protected]> |
19
|
|
|
* @since 1.0.0 |
20
|
|
|
* |
21
|
|
|
* @property CpModule $module |
22
|
|
|
*/ |
23
|
|
|
abstract class AbstractController extends Controller |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* The index view template path |
27
|
|
|
*/ |
28
|
|
|
const TEMPLATE_BASE = 'organizations/_cp'; |
29
|
|
|
|
30
|
|
|
/******************************************* |
31
|
|
|
* BASE PATHS |
32
|
|
|
*******************************************/ |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @return string |
36
|
|
|
*/ |
37
|
|
|
protected function getBaseActionPath(): string |
38
|
|
|
{ |
39
|
|
|
return OrganizationPlugin::getInstance()->getUniqueId() . '/cp'; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @return string |
44
|
|
|
*/ |
45
|
|
|
protected function getBaseCpPath(): string |
46
|
|
|
{ |
47
|
|
|
return OrganizationPlugin::getInstance()->getUniqueId(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param string $endpoint |
52
|
|
|
* @return string |
53
|
|
|
*/ |
54
|
|
|
protected function getBaseContinueEditingUrl(string $endpoint = ''): string |
55
|
|
|
{ |
56
|
|
|
return $this->getBaseCpPath() . $endpoint; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/******************************************* |
60
|
|
|
* VARIABLES |
61
|
|
|
*******************************************/ |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @inheritdoc |
65
|
|
|
*/ |
66
|
|
|
protected function baseVariables(array &$variables = []) |
67
|
|
|
{ |
68
|
|
|
$module = OrganizationPlugin::getInstance(); |
69
|
|
|
|
70
|
|
|
$title = Craft::t('organizations', "Organizations"); |
71
|
|
|
|
72
|
|
|
// Settings |
73
|
|
|
$variables['settings'] = $module->getSettings(); |
74
|
|
|
$variables['title'] = $title; |
75
|
|
|
|
76
|
|
|
// Path to controller actions |
77
|
|
|
$variables['baseActionPath'] = $this->getBaseActionPath(); |
78
|
|
|
|
79
|
|
|
// Path to CP |
80
|
|
|
$variables['baseCpPath'] = $this->getBaseCpPath(); |
81
|
|
|
|
82
|
|
|
// Set the "Continue Editing" URL |
83
|
|
|
$variables['continueEditingUrl'] = $this->getBaseCpPath(); |
84
|
|
|
|
85
|
|
|
// Select our sub-nav |
86
|
|
|
$variables['selectedSubnavItem'] = 'organizations.organizations'; |
87
|
|
|
|
88
|
|
|
// Breadcrumbs |
89
|
|
|
$variables['crumbs'][] = [ |
90
|
|
|
'label' => $title, |
91
|
|
|
'url' => UrlHelper::url(OrganizationPlugin::getInstance()->getUniqueId()) |
92
|
|
|
]; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/******************************************* |
96
|
|
|
* UPSERT VARIABLES |
97
|
|
|
*******************************************/ |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @param array $variables |
101
|
|
|
*/ |
102
|
|
|
protected function insertVariables(array &$variables) |
103
|
|
|
{ |
104
|
|
|
// apply base view variables |
105
|
|
|
$this->baseVariables($variables); |
106
|
|
|
|
107
|
|
|
// Set the "Continue Editing" URL |
108
|
|
|
$variables['continueEditingUrl'] = $this->getBaseContinueEditingUrl('/{id}'); |
109
|
|
|
|
110
|
|
|
// Append title |
111
|
|
|
$variables['title'] .= ' - ' . Craft::t('organizations', 'New'); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|