1 | <?php |
||
40 | class HubSpot extends Plugin |
||
41 | { |
||
42 | use LoggerTrait; |
||
43 | |||
44 | /** |
||
45 | * @var string |
||
46 | */ |
||
47 | public static $category = 'hubspot'; |
||
48 | |||
49 | /** |
||
50 | * @inheritdoc |
||
51 | */ |
||
52 | 9 | public function init() |
|
53 | { |
||
54 | 9 | parent::init(); |
|
55 | |||
56 | // Components |
||
57 | 9 | $this->setComponents([ |
|
58 | 9 | 'cache' => services\Cache::class, |
|
59 | 'connections' => services\Connections::class, |
||
60 | 'psr3Logger' => function () { |
||
61 | 9 | return Craft::createObject([ |
|
62 | 9 | 'class' => Logger::class, |
|
63 | 9 | 'logger' => static::getLogger(), |
|
|
|||
64 | 9 | 'category' => static::$category |
|
65 | ]); |
||
66 | 9 | } |
|
67 | ]); |
||
68 | |||
69 | // Modules |
||
70 | 9 | $this->setModules([ |
|
71 | 9 | 'cp' => cp\Cp::class |
|
72 | |||
73 | ]); |
||
74 | |||
75 | 9 | \Flipbox\HubSpot\HubSpot::setLogger( |
|
76 | 9 | $this->getPsrLogger() |
|
77 | ); |
||
78 | |||
79 | // Template variables |
||
80 | 9 | Event::on( |
|
81 | 9 | CraftVariable::class, |
|
82 | 9 | CraftVariable::EVENT_INIT, |
|
83 | function (Event $event) { |
||
84 | /** @var CraftVariable $variable */ |
||
85 | $variable = $event->sender; |
||
86 | $variable->set('hubspot', HubSpotVariable::class); |
||
87 | 9 | } |
|
88 | ); |
||
89 | |||
90 | // Integration template directory |
||
91 | 9 | Event::on( |
|
92 | 9 | View::class, |
|
93 | 9 | View::EVENT_REGISTER_CP_TEMPLATE_ROOTS, |
|
94 | function (RegisterTemplateRootsEvent $e) { |
||
95 | $e->roots['flipbox/integration'] = Craft::$app->getPath()->getVendorPath() . |
||
96 | '/flipboxfactory/craft-integration/src/templates'; |
||
97 | 9 | } |
|
98 | ); |
||
99 | |||
100 | // Register our field types |
||
101 | 9 | Event::on( |
|
102 | 9 | Fields::class, |
|
103 | 9 | Fields::EVENT_REGISTER_FIELD_TYPES, |
|
104 | function (RegisterComponentTypesEvent $event) { |
||
105 | $event->types[] = Companies::class; |
||
106 | $event->types[] = ContactLists::class; |
||
107 | $event->types[] = Contacts::class; |
||
108 | 9 | } |
|
109 | ); |
||
110 | |||
111 | // CP routes |
||
112 | 9 | Event::on( |
|
113 | 9 | UrlManager::class, |
|
114 | 9 | UrlManager::EVENT_REGISTER_CP_URL_RULES, |
|
115 | 9 | [self::class, 'onRegisterCpUrlRules'] |
|
116 | ); |
||
117 | |||
118 | // Make sure we have an objects table |
||
119 | 9 | if ($this->isInstalled) { |
|
120 | ObjectAssociation::ensureEnvironmentTableExists(); |
||
121 | } |
||
122 | 9 | } |
|
123 | |||
124 | /** |
||
125 | * @inheritdoc |
||
126 | */ |
||
127 | public function getCpNavItem() |
||
145 | |||
146 | /** |
||
147 | * @inheritdoc |
||
148 | * @return SettingsModel |
||
149 | */ |
||
150 | public function createSettingsModel() |
||
154 | |||
155 | /** |
||
156 | * @inheritdoc |
||
157 | * @throws \Twig_Error_Loader |
||
158 | * @throws \yii\base\Exception |
||
159 | */ |
||
160 | public function settingsHtml() |
||
166 | |||
167 | /******************************************* |
||
168 | * SERVICES |
||
169 | *******************************************/ |
||
170 | |||
171 | /** |
||
172 | * @noinspection PhpDocMissingThrowsInspection |
||
173 | * @return services\Cache |
||
174 | */ |
||
175 | 3 | public function getCache(): services\Cache |
|
181 | |||
182 | /** |
||
183 | * @noinspection PhpDocMissingThrowsInspection |
||
184 | * @return services\Connections |
||
185 | */ |
||
186 | 3 | public function getConnections(): services\Connections |
|
192 | |||
193 | /** |
||
194 | * @noinspection PhpDocMissingThrowsInspection |
||
195 | * @return Logger |
||
196 | */ |
||
197 | 9 | public function getPsrLogger(): Logger |
|
203 | |||
204 | |||
205 | /******************************************* |
||
206 | * TRANSLATE |
||
207 | *******************************************/ |
||
208 | |||
209 | /** |
||
210 | * Translates a message to the specified language. |
||
211 | * |
||
212 | * This is a shortcut method of [[\Craft::t()]]. |
||
213 | * * |
||
214 | * @param string $message the message to be translated. |
||
215 | * @param array $params the parameters that will be used to replace the corresponding placeholders in the message. |
||
216 | * @param string $language the language code (e.g. `en-US`, `en`). If this is null, the current |
||
217 | * [[\yii\base\Application::language|application language]] will be used. |
||
218 | * @return string the translated message. |
||
219 | */ |
||
220 | public static function t($message, $params = [], $language = null) |
||
224 | |||
225 | |||
226 | /******************************************* |
||
227 | * MODULES |
||
228 | *******************************************/ |
||
229 | |||
230 | /** |
||
231 | * @noinspection PhpDocMissingThrowsInspection |
||
232 | * @return cp\Cp |
||
233 | */ |
||
234 | public function getCp(): cp\Cp |
||
240 | |||
241 | |||
242 | /******************************************* |
||
243 | * EVENTS |
||
244 | *******************************************/ |
||
245 | |||
246 | /** |
||
247 | * @param RegisterUrlRulesEvent $event |
||
248 | */ |
||
249 | public static function onRegisterCpUrlRules(RegisterUrlRulesEvent $event) |
||
274 | } |
||
275 |
This method has been deprecated.