1 | <?php |
||
18 | |||
19 | class SyncTo extends AbstractIntegrationAction |
||
20 | { |
||
21 | /** |
||
22 | * @inheritdoc |
||
23 | */ |
||
24 | public function getTriggerLabel(): string |
||
25 | { |
||
26 | return HubSpot::t('Create HubSpot Object from Element'); |
||
27 | } |
||
28 | |||
29 | /** |
||
30 | * @inheritdoc |
||
31 | */ |
||
32 | public function getConfirmationMessage() |
||
38 | |||
39 | /** |
||
40 | * @inheritdoc |
||
41 | * @throws HttpException |
||
42 | * @throws \Throwable |
||
43 | */ |
||
44 | public function performAction(Integrations $field, ElementInterface $element): bool |
||
45 | { |
||
46 | if (!$field instanceof ObjectsFieldInterface) { |
||
47 | $this->setMessage("Invalid field type."); |
||
48 | return false; |
||
49 | } |
||
50 | |||
51 | /** @var IntegrationAssociationQuery $query */ |
||
52 | if (null === ($query = $element->getFieldValue($field->handle))) { |
||
53 | throw new HttpException(400, 'Field is not associated to element'); |
||
54 | } |
||
55 | |||
56 | if (!$field->syncToHubSpot($element)) { |
||
57 | $this->setMessage("Failed to sync from HubSpot Object"); |
||
58 | return false; |
||
59 | } |
||
60 | |||
61 | // Reset |
||
62 | $element->setFieldValue($field->handle, null); |
||
63 | |||
64 | $this->id = $query->select(['objectId'])->scalar(); |
||
65 | |||
66 | $this->setMessage("Sync to HubSpot executed successfully"); |
||
70 |