|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @copyright Copyright (c) Flipbox Digital Limited |
|
5
|
|
|
* @license https://flipboxfactory.com/software/force/license |
|
6
|
|
|
* @link https://www.flipboxfactory.com/software/force/ |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace flipbox\hubspot\cp\actions\fields; |
|
10
|
|
|
|
|
11
|
|
|
use craft\base\ElementInterface; |
|
12
|
|
|
use flipbox\ember\actions\traits\Manage; |
|
13
|
|
|
use flipbox\force\criteria\SObjectCriteria; |
|
14
|
|
|
use flipbox\force\fields\actions\SObjectRowActionInterface; |
|
15
|
|
|
use flipbox\force\fields\SObjects; |
|
16
|
|
|
use flipbox\force\Force; |
|
17
|
|
|
use yii\base\Action; |
|
18
|
|
|
use yii\web\HttpException; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Performs an action on an individual field row |
|
22
|
|
|
* |
|
23
|
|
|
* @author Flipbox Factory <[email protected]> |
|
24
|
|
|
* @since 1.0.0 |
|
25
|
|
|
*/ |
|
26
|
|
|
class PerformItemAction extends Action |
|
27
|
|
|
{ |
|
28
|
|
|
use traits\ElementResolverTrait, |
|
29
|
|
|
traits\FieldResolverTrait, |
|
30
|
|
|
Manage; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @param string $field |
|
34
|
|
|
* @param string $element |
|
35
|
|
|
* @param string|null $action |
|
36
|
|
|
* @param string|null $id |
|
37
|
|
|
* @return mixed |
|
38
|
|
|
* @throws HttpException |
|
39
|
|
|
* @throws \craft\errors\MissingComponentException |
|
40
|
|
|
* @throws \yii\base\InvalidConfigException |
|
41
|
|
|
*/ |
|
42
|
|
|
public function run(string $field, string $element, string $action, string $id) |
|
43
|
|
|
{ |
|
44
|
|
|
$field = $this->resolveField($field); |
|
45
|
|
|
$element = $this->resolveElement($element); |
|
46
|
|
|
$criteria = $this->resolveCriteria($field, $element, $id); |
|
47
|
|
|
|
|
48
|
|
|
$availableActions = Force::getInstance()->getSObjectsField()->getRowActions($field, $element); |
|
49
|
|
|
|
|
50
|
|
|
foreach ($availableActions as $availableAction) { |
|
51
|
|
|
if ($action === get_class($availableAction)) { |
|
52
|
|
|
$action = $availableAction; |
|
53
|
|
|
break; |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
if (!$action instanceof SObjectRowActionInterface) { |
|
|
|
|
|
|
58
|
|
|
throw new HttpException(400, 'Field action is not supported by the field'); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
return $this->runInternal($action, $field, $element, $criteria); |
|
|
|
|
|
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @param SObjectRowActionInterface $action |
|
66
|
|
|
* @param SObjects $field |
|
67
|
|
|
* @param ElementInterface $element |
|
68
|
|
|
* @param SObjectCriteria $criteria |
|
69
|
|
|
* @return mixed |
|
70
|
|
|
* @throws \yii\web\UnauthorizedHttpException |
|
71
|
|
|
*/ |
|
72
|
|
|
protected function runInternal( |
|
73
|
|
|
SObjectRowActionInterface $action, |
|
74
|
|
|
SObjects $field, |
|
75
|
|
|
ElementInterface $element, |
|
76
|
|
|
SObjectCriteria $criteria |
|
77
|
|
|
) { |
|
78
|
|
|
// Check access |
|
79
|
|
|
if (($access = $this->checkAccess($action, $field, $element, $criteria)) !== true) { |
|
80
|
|
|
return $access; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
if (!$this->performAction($action, $field, $element, $criteria)) { |
|
84
|
|
|
return $this->handleFailResponse($action); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
return $this->handleSuccessResponse($action); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @param SObjectRowActionInterface $action |
|
92
|
|
|
* @param SObjects $field |
|
93
|
|
|
* @param ElementInterface $element |
|
94
|
|
|
* @param SObjectCriteria $criteria |
|
95
|
|
|
* @return bool |
|
96
|
|
|
*/ |
|
97
|
|
|
public function performAction( |
|
98
|
|
|
SObjectRowActionInterface $action, |
|
99
|
|
|
SObjects $field, |
|
100
|
|
|
ElementInterface $element, |
|
101
|
|
|
SObjectCriteria $criteria |
|
102
|
|
|
): bool { |
|
103
|
|
|
return $action->performAction($field, $element, $criteria); |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.jsonfile (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.jsonto be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
requireorrequire-devsection?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceofchecks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.