Path: blob/master/src/infrastructure/customfield/herald/PhabricatorCustomFieldHeraldAction.php
12241 views
<?php12final class PhabricatorCustomFieldHeraldAction extends HeraldAction {34const ACTIONCONST = 'herald.action.custom';56const DO_SET_FIELD = 'do.set-custom-field';78private $customField;910public function setCustomField(PhabricatorCustomField $custom_field) {11$this->customField = $custom_field;12return $this;13}1415public function getCustomField() {16return $this->customField;17}1819public function getActionGroupKey() {20return PhabricatorCustomFieldHeraldActionGroup::ACTIONGROUPKEY;21}2223public function supportsObject($object) {24return ($object instanceof PhabricatorCustomFieldInterface);25}2627public function supportsRuleType($rule_type) {28return true;29}3031public function getActionsForObject($object) {32$viewer = PhabricatorUser::getOmnipotentUser();33$role = PhabricatorCustomField::ROLE_HERALDACTION;3435$field_list = PhabricatorCustomField::getObjectFields($object, $role)36->setViewer($viewer)37->readFieldsFromStorage($object);3839$map = array();40foreach ($field_list->getFields() as $field) {41$key = $field->getFieldKey();42$map[$key] = id(new self())43->setCustomField($field);44}4546return $map;47}4849public function applyEffect($object, HeraldEffect $effect) {50$field = $this->getCustomField();51$value = $effect->getTarget();52$adapter = $this->getAdapter();5354$old_value = $field->getOldValueForApplicationTransactions();55$new_value = id(clone $field)56->setValueFromApplicationTransactions($value)57->getValueForStorage();5859$xaction = $adapter->newTransaction()60->setTransactionType(PhabricatorTransactions::TYPE_CUSTOMFIELD)61->setMetadataValue('customfield:key', $field->getFieldKey())62->setOldValue($old_value)63->setNewValue($new_value);6465$adapter->queueTransaction($xaction);6667$this->logEffect(self::DO_SET_FIELD, $value);68}6970public function getHeraldActionName() {71return $this->getCustomField()->getHeraldActionName();72}7374public function getHeraldActionStandardType() {75return $this->getCustomField()->getHeraldActionStandardType();76}7778protected function getDatasource() {79return $this->getCustomField()->getHeraldActionDatasource();80}8182public function renderActionDescription($value) {83return $this->getCustomField()->getHeraldActionDescription($value);84}8586protected function getActionEffectMap() {87return array(88self::DO_SET_FIELD => array(89'icon' => 'fa-pencil',90'color' => 'green',91'name' => pht('Set Field Value'),92),93);94}9596protected function renderActionEffectDescription($type, $data) {97switch ($type) {98case self::DO_SET_FIELD:99return $this->getCustomField()->getHeraldActionEffectDescription($data);100}101}102103104}105106107