@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at upstream/main 111 lines 2.8 kB view raw
1<?php 2 3final class PhabricatorProjectTriggerRemoveProjectsRule 4 extends PhabricatorProjectTriggerRule { 5 6 const TRIGGERTYPE = 'task.projects.remove'; 7 8 public function getSelectControlname() { 9 return pht('Remove project tags'); 10 } 11 12 protected function getValueForEditorField() { 13 return $this->getDatasource()->getWireTokens($this->getValue()); 14 } 15 16 protected function assertValidRuleRecordFormat($value) { 17 if (!is_array($value)) { 18 throw new Exception( 19 pht( 20 'Remove project rule value should be a list, but is not '. 21 '(value is "%s").', 22 phutil_describe_type($value))); 23 } 24 } 25 26 protected function assertValidRuleRecordValue($value) { 27 if (!$value) { 28 throw new Exception( 29 pht( 30 'You must select at least one project tag to remove.')); 31 } 32 } 33 34 protected function newDropTransactions($object, $value) { 35 $project_edge_type = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST; 36 37 $xaction = $object->getApplicationTransactionTemplate() 38 ->setTransactionType(PhabricatorTransactions::TYPE_EDGE) 39 ->setMetadataValue('edge:type', $project_edge_type) 40 ->setNewValue( 41 array( 42 '-' => array_fuse($value), 43 )); 44 45 return array($xaction); 46 } 47 48 protected function newDropEffects($value) { 49 return array( 50 $this->newEffect() 51 ->setIcon('fa-briefcase', 'red') 52 ->setContent($this->getRuleViewDescription($value)), 53 ); 54 } 55 56 protected function getDefaultValue() { 57 return null; 58 } 59 60 protected function getPHUIXControlType() { 61 return 'tokenizer'; 62 } 63 64 private function getDatasource() { 65 return id(new PhabricatorProjectDatasource()) 66 ->setViewer($this->getViewer()); 67 } 68 69 protected function getPHUIXControlSpecification() { 70 $template = id(new AphrontTokenizerTemplateView()) 71 ->setViewer($this->getViewer()); 72 73 $template_markup = $template->render(); 74 $datasource = $this->getDatasource(); 75 76 return array( 77 'markup' => (string)hsprintf('%s', $template_markup), 78 'config' => array( 79 'src' => $datasource->getDatasourceURI(), 80 'browseURI' => $datasource->getBrowseURI(), 81 'placeholder' => $datasource->getPlaceholderText(), 82 'limit' => $datasource->getLimit(), 83 ), 84 'value' => null, 85 ); 86 } 87 88 public function getRuleViewLabel() { 89 return pht('Remove Project Tags'); 90 } 91 92 public function getRuleViewDescription($value) { 93 return pht( 94 'Remove project tags: %s.', 95 phutil_tag( 96 'strong', 97 array(), 98 $this->getViewer() 99 ->renderHandleList($value) 100 ->setAsInline(true) 101 ->render())); 102 } 103 104 public function getRuleViewIcon($value) { 105 return id(new PHUIIconView()) 106 ->setIcon('fa-briefcase', 'red'); 107 } 108 109 110 111}