@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 127 lines 3.2 kB view raw
1<?php 2 3/** 4 * Trigger Rule that Adds Subscribers 5 * 6 * This may be useful to automatically engage some 7 * Users or Project Tags on certain Workboard areas. 8 * 9 * This class was adapted from these classes: 10 * - PhabricatorProjectTriggerAddProjectsRule 11 * - PhabricatorProjectTriggerManiphestOwnerRule 12 * 13 * https://we.phorge.it/T15162 14 */ 15final class PhabricatorProjectTriggerAddSubscribersRule 16 extends PhabricatorProjectTriggerRule { 17 18 const TRIGGERTYPE = 'task.subscriber.add'; 19 20 public function getSelectControlName() { 21 return pht('Add subscribers'); 22 } 23 24 protected function getValueForEditorField() { 25 return $this->getDatasource()->getWireTokens($this->getValue()); 26 } 27 28 protected function assertValidRuleRecordFormat($value) { 29 if (!is_array($value)) { 30 throw new Exception( 31 pht( 32 'Add subscribers rule value should be a list, but is not '. 33 '(value is "%s").', 34 phutil_describe_type($value))); 35 } 36 } 37 38 protected function assertValidRuleRecordValue($value) { 39 if (!$value) { 40 throw new Exception( 41 pht( 42 'You must select at least one user or project tag to add.')); 43 } 44 } 45 46 protected function newDropTransactions($object, $value) { 47 $subscriber_edge_type = PhabricatorObjectHasSubscriberEdgeType::EDGECONST; 48 49 $xaction = $object->getApplicationTransactionTemplate() 50 ->setTransactionType(PhabricatorTransactions::TYPE_EDGE) 51 ->setMetadataValue('edge:type', $subscriber_edge_type) 52 ->setNewValue( 53 array( 54 '+' => array_fuse($value), 55 )); 56 57 return array($xaction); 58 } 59 60 protected function newDropEffects($value) { 61 return array( 62 $this->newEffect() 63 ->setIcon('fa-briefcase') 64 ->setContent($this->getRuleViewDescription($value)), 65 ); 66 } 67 68 protected function getDefaultValue() { 69 return null; 70 } 71 72 protected function getPHUIXControlType() { 73 return 'tokenizer'; 74 } 75 76 private function getDatasource() { 77 $datasource = new PhabricatorProjectOrUserDatasource(); 78 79 if ($this->getViewer()) { 80 $datasource->setViewer($this->getViewer()); 81 } 82 83 return $datasource; 84 } 85 86 protected function getPHUIXControlSpecification() { 87 $template = id(new AphrontTokenizerTemplateView()) 88 ->setViewer($this->getViewer()); 89 90 $template_markup = $template->render(); 91 $datasource = $this->getDatasource(); 92 93 return array( 94 'markup' => (string)hsprintf('%s', $template_markup), 95 'config' => array( 96 'src' => $datasource->getDatasourceURI(), 97 'browseURI' => $datasource->getBrowseURI(), 98 'placeholder' => $datasource->getPlaceholderText(), 99 'limit' => $datasource->getLimit(), 100 ), 101 'value' => null, 102 ); 103 } 104 105 public function getRuleViewLabel() { 106 return pht('Add subscribers'); 107 } 108 109 public function getRuleViewDescription($value) { 110 return pht( 111 'Add subscribers: %s.', 112 phutil_tag( 113 'strong', 114 array(), 115 $this->getViewer() 116 ->renderHandleList($value) 117 ->setAsInline(true) 118 ->render())); 119 } 120 121 public function getRuleViewIcon($value) { 122 return id(new PHUIIconView()) 123 ->setIcon('fa-users', 'green'); 124 } 125 126 127}