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; |
10
|
|
|
|
11
|
|
|
use Craft; |
12
|
|
|
use flipbox\craft\hubspot\connections\ApplicationKeyConnection; |
13
|
|
|
use flipbox\craft\hubspot\connections\SavableConnectionInterface; |
14
|
|
|
use flipbox\craft\hubspot\events\RegisterConnectionsEvent; |
15
|
|
|
use flipbox\hubspot\HubSpot; |
16
|
|
|
use yii\base\Module as BaseModule; |
17
|
|
|
use yii\web\NotFoundHttpException; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @author Flipbox Factory <[email protected]> |
21
|
|
|
* @since 1.0.0 |
22
|
|
|
* |
23
|
|
|
* @property HubSpot $module |
24
|
|
|
*/ |
25
|
|
|
class Cp extends BaseModule |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var SavableConnectionInterface[] |
29
|
|
|
*/ |
30
|
|
|
private $registeredConnections; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @inheritdoc |
34
|
|
|
* @throws NotFoundHttpException |
35
|
|
|
*/ |
36
|
|
|
public function beforeAction($action) |
37
|
|
|
{ |
38
|
|
|
if (!Craft::$app->request->getIsCpRequest()) { |
39
|
|
|
throw new NotFoundHttpException(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
return parent::beforeAction($action); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/******************************************* |
46
|
|
|
* CONNECTIONS |
47
|
|
|
*******************************************/ |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @return SavableConnectionInterface[] |
51
|
|
|
*/ |
52
|
|
|
public function getAvailableConnections(): array |
53
|
|
|
{ |
54
|
|
|
if ($this->registeredConnections === null) { |
55
|
|
|
$event = new RegisterConnectionsEvent([ |
56
|
|
|
'connections' => [ |
57
|
|
|
ApplicationKeyConnection::class |
58
|
|
|
] |
59
|
|
|
]); |
60
|
|
|
|
61
|
|
|
$this->trigger( |
62
|
|
|
$event::REGISTER_CONNECTIONS, |
63
|
|
|
$event |
64
|
|
|
); |
65
|
|
|
|
66
|
|
|
$this->registeredConnections = $event->connections; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
return $this->registeredConnections; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|