1 | <?php |
||
42 | class HubSpot extends Plugin |
||
43 | { |
||
44 | use LoggerTrait; |
||
45 | |||
46 | /** |
||
47 | * @var string |
||
48 | */ |
||
49 | public static $category = 'hubspot'; |
||
50 | |||
51 | /** |
||
52 | * @inheritdoc |
||
53 | */ |
||
54 | 9 | public function init() |
|
55 | { |
||
56 | 9 | parent::init(); |
|
57 | |||
58 | // Components |
||
59 | 9 | $this->setComponents([ |
|
60 | 9 | 'cache' => services\Cache::class, |
|
61 | 'connections' => services\Connections::class, |
||
62 | 3 | 'psr3Logger' => function () { |
|
63 | 9 | return Craft::createObject([ |
|
64 | 9 | 'class' => Logger::class, |
|
65 | 9 | 'logger' => static::getLogger(), |
|
|
|||
66 | 9 | 'category' => static::$category |
|
67 | ]); |
||
68 | 9 | }, |
|
69 | 'visitor' => services\Visitor::class |
||
70 | ]); |
||
71 | |||
72 | // Modules |
||
73 | 9 | $this->setModules([ |
|
74 | 9 | 'cp' => cp\Cp::class |
|
75 | |||
76 | ]); |
||
77 | |||
78 | 9 | \Flipbox\HubSpot\HubSpot::setLogger( |
|
79 | 9 | $this->getPsrLogger() |
|
80 | ); |
||
81 | |||
82 | // Template variables |
||
83 | 9 | Event::on( |
|
84 | 9 | CraftVariable::class, |
|
85 | 9 | CraftVariable::EVENT_INIT, |
|
86 | 3 | function (Event $event) { |
|
87 | /** @var CraftVariable $variable */ |
||
88 | $variable = $event->sender; |
||
89 | $variable->set('hubspot', HubSpotVariable::class); |
||
90 | 9 | } |
|
91 | ); |
||
92 | |||
93 | // Integration template directory |
||
94 | 9 | Event::on( |
|
95 | 9 | View::class, |
|
96 | 9 | View::EVENT_REGISTER_CP_TEMPLATE_ROOTS, |
|
97 | 3 | function (RegisterTemplateRootsEvent $e) { |
|
98 | $e->roots['flipbox/integration'] = Craft::$app->getPath()->getVendorPath() . |
||
99 | '/flipboxfactory/craft-integration/src/templates'; |
||
100 | 9 | } |
|
101 | ); |
||
102 | |||
103 | // Register our field types |
||
104 | 9 | Event::on( |
|
105 | 9 | Fields::class, |
|
106 | 9 | Fields::EVENT_REGISTER_FIELD_TYPES, |
|
107 | 3 | function (RegisterComponentTypesEvent $event) { |
|
108 | $event->types[] = Companies::class; |
||
109 | $event->types[] = ContactLists::class; |
||
110 | $event->types[] = Contacts::class; |
||
111 | 9 | } |
|
112 | ); |
||
113 | |||
114 | // CP routes |
||
115 | 9 | Event::on( |
|
116 | 9 | UrlManager::class, |
|
117 | 9 | UrlManager::EVENT_REGISTER_CP_URL_RULES, |
|
118 | 9 | [self::class, 'onRegisterCpUrlRules'] |
|
119 | ); |
||
120 | |||
121 | // Make sure we have an objects table |
||
122 | 9 | if ($this->isInstalled) { |
|
123 | ObjectAssociation::ensureEnvironmentTableExists(); |
||
124 | } |
||
125 | 9 | } |
|
126 | |||
127 | /** |
||
128 | * @inheritdoc |
||
129 | */ |
||
130 | public function getCpNavItem() |
||
152 | |||
153 | /** |
||
154 | * @inheritdoc |
||
155 | * @return SettingsModel |
||
156 | */ |
||
157 | public function createSettingsModel() |
||
161 | |||
162 | /** |
||
163 | * @inheritdoc |
||
164 | */ |
||
165 | public function settingsHtml() |
||
173 | |||
174 | /******************************************* |
||
175 | * SERVICES |
||
176 | *******************************************/ |
||
177 | |||
178 | /** |
||
179 | * @noinspection PhpDocMissingThrowsInspection |
||
180 | * @return services\Cache |
||
181 | */ |
||
182 | 3 | public function getCache(): services\Cache |
|
188 | |||
189 | /** |
||
190 | * @noinspection PhpDocMissingThrowsInspection |
||
191 | * @return services\Connections |
||
192 | */ |
||
193 | 3 | public function getConnections(): services\Connections |
|
199 | |||
200 | /** |
||
201 | * @noinspection PhpDocMissingThrowsInspection |
||
202 | * @return Logger |
||
203 | */ |
||
204 | 9 | public function getPsrLogger(): Logger |
|
210 | |||
211 | /** |
||
212 | * @noinspection PhpDocMissingThrowsInspection |
||
213 | * @return Visitor |
||
214 | */ |
||
215 | public function getVisitor(): Visitor |
||
221 | |||
222 | /******************************************* |
||
223 | * TRANSLATE |
||
224 | *******************************************/ |
||
225 | |||
226 | /** |
||
227 | * Translates a message to the specified language. |
||
228 | * |
||
229 | * This is a shortcut method of [[\Craft::t()]]. |
||
230 | * * |
||
231 | * @param string $message the message to be translated. |
||
232 | * @param array $params the parameters that will be used to replace the corresponding placeholders in the message. |
||
233 | * @param string $language the language code (e.g. `en-US`, `en`). If this is null, the current |
||
234 | * [[\yii\base\Application::language|application language]] will be used. |
||
235 | * @return string the translated message. |
||
236 | */ |
||
237 | public static function t($message, $params = [], $language = null) |
||
241 | |||
242 | |||
243 | /******************************************* |
||
244 | * MODULES |
||
245 | *******************************************/ |
||
246 | |||
247 | /** |
||
248 | * @noinspection PhpDocMissingThrowsInspection |
||
249 | * @return cp\Cp |
||
250 | */ |
||
251 | public function getCp(): cp\Cp |
||
257 | |||
258 | |||
259 | /******************************************* |
||
260 | * EVENTS |
||
261 | *******************************************/ |
||
262 | |||
263 | /** |
||
264 | * @param RegisterUrlRulesEvent $event |
||
265 | */ |
||
266 | public static function onRegisterCpUrlRules(RegisterUrlRulesEvent $event) |
||
295 | } |
||
296 |
This method has been deprecated.