|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @copyright Copyright (c) Flipbox Digital Limited |
|
5
|
|
|
* @license https://flipboxfactory.com/software/hubspot/license |
|
6
|
|
|
* @link https://www.flipboxfactory.com/software/hubspot/ |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace flipbox\craft\hubspot\cp\controllers\view; |
|
10
|
|
|
|
|
11
|
|
|
use Craft; |
|
12
|
|
|
use craft\web\Controller; |
|
13
|
|
|
use flipbox\craft\ember\helpers\UrlHelper; |
|
14
|
|
|
use flipbox\craft\hubspot\cp\Cp as CpModule; |
|
15
|
|
|
use flipbox\craft\hubspot\HubSpot; |
|
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 = 'hubspot' . '/_cp'; |
|
29
|
|
|
|
|
30
|
|
|
/******************************************* |
|
31
|
|
|
* BASE PATHS |
|
32
|
|
|
*******************************************/ |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @return string |
|
36
|
|
|
*/ |
|
37
|
|
|
protected function getBaseActionPath(): string |
|
38
|
|
|
{ |
|
39
|
|
|
return HubSpot::getInstance()->getUniqueId() . '/cp'; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @return string |
|
44
|
|
|
*/ |
|
45
|
|
|
protected function getBaseCpPath(): string |
|
46
|
|
|
{ |
|
47
|
|
|
return HubSpot::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 = HubSpot::getInstance(); |
|
69
|
|
|
|
|
70
|
|
|
$title = HubSpot::t("HubSpot"); |
|
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
|
|
|
if (!$activeSubNav = Craft::$app->getRequest()->getSegment(2)) { |
|
87
|
|
|
$activeSubNav = 'queries'; |
|
88
|
|
|
} |
|
89
|
|
|
$variables['selectedSubnavItem'] = 'hubspot.' . $activeSubNav; |
|
90
|
|
|
|
|
91
|
|
|
// Breadcrumbs |
|
92
|
|
|
$variables['crumbs'][] = [ |
|
93
|
|
|
'label' => $title, |
|
94
|
|
|
'url' => UrlHelper::url(HubSpot::getInstance()->getUniqueId()) |
|
95
|
|
|
]; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/******************************************* |
|
99
|
|
|
* UPSERT VARIABLES |
|
100
|
|
|
*******************************************/ |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @param array $variables |
|
104
|
|
|
*/ |
|
105
|
|
|
protected function insertVariables(array &$variables) |
|
106
|
|
|
{ |
|
107
|
|
|
// apply base view variables |
|
108
|
|
|
$this->baseVariables($variables); |
|
109
|
|
|
|
|
110
|
|
|
// Set the "Continue Editing" URL |
|
111
|
|
|
$variables['continueEditingUrl'] = $this->getBaseContinueEditingUrl('/{id}'); |
|
112
|
|
|
|
|
113
|
|
|
// Append title |
|
114
|
|
|
$variables['title'] .= ' - ' . HubSpot::t('New'); |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|