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 $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
|
|
|
|
45
|
|
|
$event = new CreatePayloadFromElementEvent([ |
46
|
|
|
'payload' => $this->createPayload($element, $field) |
47
|
|
|
]); |
48
|
|
|
|
49
|
|
|
$name = $event::eventName( |
50
|
|
|
$field->handle, |
51
|
|
|
$this->action |
52
|
|
|
); |
53
|
|
|
|
54
|
|
|
HubSpot::info(sprintf( |
55
|
|
|
"Create payload: Event '%s', Element '%s'", |
56
|
|
|
$name, |
57
|
|
|
$element->id . ' - ' . $element->title |
|
|
|
|
58
|
|
|
), __METHOD__); |
59
|
|
|
|
60
|
|
|
$element->trigger($name, $event); |
61
|
|
|
|
62
|
|
|
return $event->getPayload(); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param ElementInterface $element |
67
|
|
|
* @param ObjectsFieldInterface $field |
68
|
|
|
* @return array |
69
|
|
|
* |
70
|
|
|
* @noinspection PhpUnusedParameterInspection |
71
|
|
|
*/ |
72
|
|
|
public function createPayload( |
73
|
|
|
ElementInterface $element, |
|
|
|
|
74
|
|
|
ObjectsFieldInterface $field |
|
|
|
|
75
|
|
|
): array { |
76
|
|
|
/** @var Element $element */ |
77
|
|
|
|
78
|
|
|
return []; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: