1 | <?php |
||
35 | class Objects extends Field |
||
36 | { |
||
37 | /** |
||
38 | * The action event name |
||
39 | */ |
||
40 | const EVENT_REGISTER_ACTIONS = 'registerActions'; |
||
41 | |||
42 | /** |
||
43 | * The action event name |
||
44 | */ |
||
45 | const EVENT_REGISTER_AVAILABLE_ACTIONS = 'registerAvailableActions'; |
||
46 | |||
47 | /** |
||
48 | * The item action event name |
||
49 | */ |
||
50 | const EVENT_REGISTER_ITEM_ACTIONS = 'registerItemActions'; |
||
51 | |||
52 | /** |
||
53 | * The item action event name |
||
54 | */ |
||
55 | const EVENT_REGISTER_AVAILABLE_ITEM_ACTIONS = 'registerAvailableItemActions'; |
||
56 | |||
57 | /** |
||
58 | * The input template path |
||
59 | */ |
||
60 | const INPUT_TEMPLATE_PATH = 'hubspot/_components/fieldtypes/Objects/input'; |
||
61 | |||
62 | /** |
||
63 | * The default HubSpot Resource Id (if none exists) |
||
64 | */ |
||
65 | const DEFAULT_HUBSPOT_ID = 'UNKNOWN_ID'; |
||
66 | |||
67 | /** |
||
68 | * @var string |
||
69 | */ |
||
70 | public $object; |
||
71 | |||
72 | /** |
||
73 | * @var int|null |
||
74 | */ |
||
75 | public $min; |
||
76 | |||
77 | /** |
||
78 | * @var int|null |
||
79 | */ |
||
80 | public $max; |
||
81 | |||
82 | /** |
||
83 | * @var string |
||
84 | */ |
||
85 | public $viewUrl = ''; |
||
86 | |||
87 | /** |
||
88 | * @var string |
||
89 | */ |
||
90 | public $listUrl = ''; |
||
91 | |||
92 | /** |
||
93 | * @var array |
||
94 | */ |
||
95 | public $selectedActions = []; |
||
96 | |||
97 | /** |
||
98 | * @var array |
||
99 | */ |
||
100 | public $selectedItemActions = []; |
||
101 | |||
102 | /** |
||
103 | * @var string|null |
||
104 | */ |
||
105 | public $selectionLabel; |
||
106 | |||
107 | /** |
||
108 | * @inheritdoc |
||
109 | */ |
||
110 | public static function displayName(): string |
||
114 | |||
115 | /** |
||
116 | * @inheritdoc |
||
117 | */ |
||
118 | public static function defaultSelectionLabel(): string |
||
122 | |||
123 | /** |
||
124 | * @inheritdoc |
||
125 | */ |
||
126 | public static function hasContentColumn(): bool |
||
130 | |||
131 | /******************************************* |
||
132 | * VALIDATION |
||
133 | *******************************************/ |
||
134 | |||
135 | /** |
||
136 | * @inheritdoc |
||
137 | */ |
||
138 | public function getElementValidationRules(): array |
||
157 | |||
158 | /******************************************* |
||
159 | * CRUD |
||
160 | *******************************************/ |
||
161 | |||
162 | /** |
||
163 | * @return CRUDInterface |
||
164 | * @throws InvalidConfigException |
||
165 | */ |
||
166 | public function getResource(): CRUDInterface |
||
180 | |||
181 | /******************************************* |
||
182 | * CRITERIA |
||
183 | *******************************************/ |
||
184 | |||
185 | /** |
||
186 | * @return array |
||
187 | */ |
||
188 | protected function getResourceCriteriaMap(): array |
||
189 | { |
||
190 | return [ |
||
191 | Companies::HUBSPOT_RESOURCE => function (ObjectAssociation $record = null) { |
||
192 | return [ |
||
193 | 'class' => CompanyCriteria::class, |
||
194 | 'id' => $record ? $record->objectId : self::DEFAULT_HUBSPOT_ID |
||
195 | ]; |
||
196 | }, |
||
197 | Contacts::HUBSPOT_RESOURCE => function (ObjectAssociation $record = null) { |
||
198 | return [ |
||
199 | 'class' => ContactCriteria::class, |
||
200 | 'id' => $record ? $record->objectId : self::DEFAULT_HUBSPOT_ID |
||
201 | ]; |
||
202 | }, |
||
203 | ContactLists::HUBSPOT_RESOURCE => function (ObjectAssociation $record = null) { |
||
204 | return [ |
||
205 | 'class' => ContactListCriteria::class, |
||
206 | 'id' => $record ? $record->objectId : self::DEFAULT_HUBSPOT_ID |
||
207 | ]; |
||
208 | } |
||
209 | ]; |
||
210 | } |
||
211 | |||
212 | /** |
||
213 | * @param ObjectAssociation|null $record |
||
214 | * @param array $config |
||
215 | * @return ObjectCriteriaInterface |
||
216 | * @throws \yii\base\InvalidConfigException |
||
217 | */ |
||
218 | public function createResourceCriteria( |
||
247 | |||
248 | /******************************************* |
||
249 | * VALUE |
||
250 | *******************************************/ |
||
251 | |||
252 | /** |
||
253 | * @inheritdoc |
||
254 | */ |
||
255 | public function normalizeValue($value, ElementInterface $element = null) |
||
263 | |||
264 | |||
265 | /******************************************* |
||
266 | * ELEMENT |
||
267 | *******************************************/ |
||
268 | |||
269 | /** |
||
270 | * @inheritdoc |
||
271 | */ |
||
272 | public function modifyElementsQuery(ElementQueryInterface $query, $value) |
||
280 | |||
281 | |||
282 | /******************************************* |
||
283 | * RULES |
||
284 | *******************************************/ |
||
285 | |||
286 | /** |
||
287 | * @inheritdoc |
||
288 | */ |
||
289 | public function rules() |
||
316 | |||
317 | /******************************************* |
||
318 | * SEARCH |
||
319 | *******************************************/ |
||
320 | |||
321 | /** |
||
322 | * @param ObjectAssociationQuery $value |
||
323 | * @inheritdoc |
||
324 | */ |
||
325 | public function getSearchKeywords($value, ElementInterface $element): string |
||
335 | |||
336 | /******************************************* |
||
337 | * VIEWS |
||
338 | *******************************************/ |
||
339 | |||
340 | /** |
||
341 | * @param ObjectAssociationQuery $value |
||
342 | * @inheritdoc |
||
343 | * @throws \Twig_Error_Loader |
||
344 | * @throws \yii\base\Exception |
||
345 | */ |
||
346 | public function getInputHtml($value, ElementInterface $element = null): string |
||
351 | |||
352 | /** |
||
353 | * @inheritdoc |
||
354 | * @throws \Twig_Error_Loader |
||
355 | * @throws \yii\base\Exception |
||
356 | */ |
||
357 | public function getSettingsHtml() |
||
361 | |||
362 | /******************************************* |
||
363 | * EVENTS |
||
364 | *******************************************/ |
||
365 | |||
366 | /** |
||
367 | * @inheritdoc |
||
368 | * @throws \Exception |
||
369 | */ |
||
370 | public function afterElementSave(ElementInterface $element, bool $isNew) |
||
379 | } |
||
380 |