1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @noinspection PhpUnusedParameterInspection |
5
|
|
|
* |
6
|
|
|
* @copyright Copyright (c) Flipbox Digital Limited |
7
|
|
|
* @license https://github.com/flipbox/hubspot/blob/master/LICENSE.md |
8
|
|
|
* @link https://github.com/flipbox/hubspot |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace flipbox\craft\hubspot\transformers; |
12
|
|
|
|
13
|
|
|
use craft\base\Element; |
14
|
|
|
use craft\base\ElementInterface; |
15
|
|
|
use flipbox\craft\hubspot\events\CreatePayloadFromElementEvent; |
16
|
|
|
use flipbox\craft\hubspot\fields\Objects; |
17
|
|
|
use flipbox\craft\hubspot\fields\ObjectsFieldInterface; |
18
|
|
|
use flipbox\craft\hubspot\HubSpot; |
19
|
|
|
use yii\base\BaseObject; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @author Flipbox Factory <[email protected]> |
23
|
|
|
* @since 1.0.0 |
24
|
|
|
*/ |
25
|
|
|
class CreateUpsertPayloadFromElement extends BaseObject |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* An action used to assemble a unique event name. |
29
|
|
|
* |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
public $action; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param ElementInterface $element |
36
|
|
|
* @param ObjectsFieldInterface $field |
37
|
|
|
* @return array |
38
|
|
|
*/ |
39
|
|
|
public function __invoke( |
40
|
|
|
ElementInterface $element, |
41
|
|
|
ObjectsFieldInterface $field |
42
|
|
|
): array { |
43
|
|
|
/** @var Objects $field */ |
44
|
|
|
/** @var Element $element */ |
45
|
|
|
|
46
|
|
|
$event = new CreatePayloadFromElementEvent([ |
47
|
|
|
'payload' => $this->createPayload($element, $field) |
48
|
|
|
]); |
49
|
|
|
|
50
|
|
|
$name = $event::eventName( |
51
|
|
|
$field->handle, |
52
|
|
|
$this->action |
53
|
|
|
); |
54
|
|
|
|
55
|
|
|
HubSpot::info(sprintf( |
56
|
|
|
"Create payload: Event '%s', Element '%s'", |
57
|
|
|
$name, |
58
|
|
|
$element->id . ' - ' . $element->title |
59
|
|
|
), __METHOD__); |
60
|
|
|
|
61
|
|
|
$element->trigger($name, $event); |
62
|
|
|
|
63
|
|
|
return $event->getPayload(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param ElementInterface $element |
68
|
|
|
* @param ObjectsFieldInterface $field |
69
|
|
|
* @return array |
70
|
|
|
* |
71
|
|
|
* @noinspection PhpUnusedParameterInspection |
72
|
|
|
*/ |
73
|
|
|
public function createPayload( |
74
|
|
|
ElementInterface $element, |
75
|
|
|
ObjectsFieldInterface $field |
76
|
|
|
): array { |
77
|
|
|
/** @var Element $element */ |
78
|
|
|
|
79
|
|
|
return []; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|