Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / infrastructure / customfield / herald / PhabricatorCustomFieldHeraldAction.php
blob1d35ba59a207c714cdecfdcd0b173bafcb51cb1e
1 <?php
3 final class PhabricatorCustomFieldHeraldAction extends HeraldAction {
5 const ACTIONCONST = 'herald.action.custom';
7 const DO_SET_FIELD = 'do.set-custom-field';
9 private $customField;
11 public function setCustomField(PhabricatorCustomField $custom_field) {
12 $this->customField = $custom_field;
13 return $this;
16 public function getCustomField() {
17 return $this->customField;
20 public function getActionGroupKey() {
21 return PhabricatorCustomFieldHeraldActionGroup::ACTIONGROUPKEY;
24 public function supportsObject($object) {
25 return ($object instanceof PhabricatorCustomFieldInterface);
28 public function supportsRuleType($rule_type) {
29 return true;
32 public function getActionsForObject($object) {
33 $viewer = PhabricatorUser::getOmnipotentUser();
34 $role = PhabricatorCustomField::ROLE_HERALDACTION;
36 $field_list = PhabricatorCustomField::getObjectFields($object, $role)
37 ->setViewer($viewer)
38 ->readFieldsFromStorage($object);
40 $map = array();
41 foreach ($field_list->getFields() as $field) {
42 $key = $field->getFieldKey();
43 $map[$key] = id(new self())
44 ->setCustomField($field);
47 return $map;
50 public function applyEffect($object, HeraldEffect $effect) {
51 $field = $this->getCustomField();
52 $value = $effect->getTarget();
53 $adapter = $this->getAdapter();
55 $old_value = $field->getOldValueForApplicationTransactions();
56 $new_value = id(clone $field)
57 ->setValueFromApplicationTransactions($value)
58 ->getValueForStorage();
60 $xaction = $adapter->newTransaction()
61 ->setTransactionType(PhabricatorTransactions::TYPE_CUSTOMFIELD)
62 ->setMetadataValue('customfield:key', $field->getFieldKey())
63 ->setOldValue($old_value)
64 ->setNewValue($new_value);
66 $adapter->queueTransaction($xaction);
68 $this->logEffect(self::DO_SET_FIELD, $value);
71 public function getHeraldActionName() {
72 return $this->getCustomField()->getHeraldActionName();
75 public function getHeraldActionStandardType() {
76 return $this->getCustomField()->getHeraldActionStandardType();
79 protected function getDatasource() {
80 return $this->getCustomField()->getHeraldActionDatasource();
83 public function renderActionDescription($value) {
84 return $this->getCustomField()->getHeraldActionDescription($value);
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'),
97 protected function renderActionEffectDescription($type, $data) {
98 switch ($type) {
99 case self::DO_SET_FIELD:
100 return $this->getCustomField()->getHeraldActionEffectDescription($data);