Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/infrastructure/customfield/herald/PhabricatorCustomFieldHeraldAction.php
12241 views
1
<?php
2
3
final class PhabricatorCustomFieldHeraldAction extends HeraldAction {
4
5
const ACTIONCONST = 'herald.action.custom';
6
7
const DO_SET_FIELD = 'do.set-custom-field';
8
9
private $customField;
10
11
public function setCustomField(PhabricatorCustomField $custom_field) {
12
$this->customField = $custom_field;
13
return $this;
14
}
15
16
public function getCustomField() {
17
return $this->customField;
18
}
19
20
public function getActionGroupKey() {
21
return PhabricatorCustomFieldHeraldActionGroup::ACTIONGROUPKEY;
22
}
23
24
public function supportsObject($object) {
25
return ($object instanceof PhabricatorCustomFieldInterface);
26
}
27
28
public function supportsRuleType($rule_type) {
29
return true;
30
}
31
32
public function getActionsForObject($object) {
33
$viewer = PhabricatorUser::getOmnipotentUser();
34
$role = PhabricatorCustomField::ROLE_HERALDACTION;
35
36
$field_list = PhabricatorCustomField::getObjectFields($object, $role)
37
->setViewer($viewer)
38
->readFieldsFromStorage($object);
39
40
$map = array();
41
foreach ($field_list->getFields() as $field) {
42
$key = $field->getFieldKey();
43
$map[$key] = id(new self())
44
->setCustomField($field);
45
}
46
47
return $map;
48
}
49
50
public function applyEffect($object, HeraldEffect $effect) {
51
$field = $this->getCustomField();
52
$value = $effect->getTarget();
53
$adapter = $this->getAdapter();
54
55
$old_value = $field->getOldValueForApplicationTransactions();
56
$new_value = id(clone $field)
57
->setValueFromApplicationTransactions($value)
58
->getValueForStorage();
59
60
$xaction = $adapter->newTransaction()
61
->setTransactionType(PhabricatorTransactions::TYPE_CUSTOMFIELD)
62
->setMetadataValue('customfield:key', $field->getFieldKey())
63
->setOldValue($old_value)
64
->setNewValue($new_value);
65
66
$adapter->queueTransaction($xaction);
67
68
$this->logEffect(self::DO_SET_FIELD, $value);
69
}
70
71
public function getHeraldActionName() {
72
return $this->getCustomField()->getHeraldActionName();
73
}
74
75
public function getHeraldActionStandardType() {
76
return $this->getCustomField()->getHeraldActionStandardType();
77
}
78
79
protected function getDatasource() {
80
return $this->getCustomField()->getHeraldActionDatasource();
81
}
82
83
public function renderActionDescription($value) {
84
return $this->getCustomField()->getHeraldActionDescription($value);
85
}
86
87
protected function getActionEffectMap() {
88
return array(
89
self::DO_SET_FIELD => array(
90
'icon' => 'fa-pencil',
91
'color' => 'green',
92
'name' => pht('Set Field Value'),
93
),
94
);
95
}
96
97
protected function renderActionEffectDescription($type, $data) {
98
switch ($type) {
99
case self::DO_SET_FIELD:
100
return $this->getCustomField()->getHeraldActionEffectDescription($data);
101
}
102
}
103
104
105
}
106
107