@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
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at recaptime-dev/main 168 lines 4.4 kB view raw
1<?php 2 3abstract class PhabricatorStandardCustomFieldTokenizer 4 extends PhabricatorStandardCustomFieldPHIDs { 5 6 abstract public function getDatasource(); 7 8 public function renderEditControl(array $handles) { 9 $value = $this->getFieldValue(); 10 11 $control = id(new AphrontFormTokenizerControl()) 12 ->setViewer($this->getViewer()) 13 ->setLabel($this->getFieldName()) 14 ->setName($this->getFieldKey()) 15 ->setDatasource($this->getDatasource()) 16 ->setCaption($this->getCaption()) 17 ->setError($this->getFieldError()) 18 ->setValue(nonempty($value, array())); 19 20 $limit = $this->getFieldConfigValue('limit'); 21 if ($limit) { 22 $control->setLimit($limit); 23 } 24 25 return $control; 26 } 27 28 public function appendToApplicationSearchForm( 29 PhabricatorApplicationSearchEngine $engine, 30 AphrontFormView $form, 31 $value) { 32 33 $control = id(new AphrontFormTokenizerControl()) 34 ->setLabel($this->getFieldName()) 35 ->setName($this->getFieldKey()) 36 ->setDatasource($this->newApplicationSearchDatasource()) 37 ->setValue(nonempty($value, array())); 38 39 $form->appendControl($control); 40 } 41 42 public function applyApplicationSearchConstraintToQuery( 43 PhabricatorApplicationSearchEngine $engine, 44 PhabricatorCursorPagedPolicyAwareQuery $query, 45 $value) { 46 if ($value) { 47 48 $datasource = $this->newApplicationSearchDatasource() 49 ->setViewer($this->getViewer()); 50 $value = $datasource->evaluateTokens($value); 51 52 $query->withApplicationSearchContainsConstraint( 53 $this->newStringIndex(null), 54 $value); 55 } 56 } 57 58 public function getHeraldFieldValueType($condition) { 59 return id(new HeraldTokenizerFieldValue()) 60 ->setKey('custom.'.$this->getFieldKey()) 61 ->setDatasource($this->getDatasource()); 62 } 63 64 public function getHeraldFieldStandardType() { 65 return HeraldField::STANDARD_PHID_LIST; 66 } 67 68 public function getHeraldDatasource() { 69 return $this->getDatasource(); 70 } 71 72 protected function getHTTPParameterType() { 73 return new AphrontPHIDListHTTPParameterType(); 74 } 75 76 protected function newConduitSearchParameterType() { 77 return new ConduitPHIDListParameterType(); 78 } 79 80 protected function newConduitEditParameterType() { 81 return new ConduitPHIDListParameterType(); 82 } 83 84 protected function newBulkParameterType() { 85 $datasource = $this->getDatasource(); 86 87 $limit = $this->getFieldConfigValue('limit'); 88 if ($limit) { 89 $datasource->setLimit($limit); 90 } 91 92 return id(new BulkTokenizerParameterType()) 93 ->setDatasource($datasource); 94 } 95 96 public function shouldAppearInHeraldActions() { 97 return true; 98 } 99 100 public function getHeraldActionName() { 101 return pht('Set "%s" to', $this->getFieldName()); 102 } 103 104 public function getHeraldActionDescription($value) { 105 $list = $this->renderHeraldHandleList($value); 106 return pht('Set "%s" to: %s.', $this->getFieldName(), $list); 107 } 108 109 public function getHeraldActionEffectDescription($value) { 110 return $this->renderHeraldHandleList($value); 111 } 112 113 public function getHeraldActionStandardType() { 114 return HeraldAction::STANDARD_PHID_LIST; 115 } 116 117 public function getHeraldActionDatasource() { 118 $datasource = $this->getDatasource(); 119 120 $limit = $this->getFieldConfigValue('limit'); 121 if ($limit) { 122 $datasource->setLimit($limit); 123 } 124 125 return $datasource; 126 } 127 128 private function renderHeraldHandleList($value) { 129 if (!is_array($value)) { 130 return pht('(Invalid List)'); 131 } else { 132 return $this->getViewer() 133 ->renderHandleList($value) 134 ->setAsInline(true) 135 ->render(); 136 } 137 } 138 139 protected function newApplicationSearchDatasource() { 140 $datasource = $this->getDatasource(); 141 142 return id(new PhabricatorCustomFieldApplicationSearchDatasource()) 143 ->setDatasource($datasource); 144 } 145 146 protected function newCommentAction() { 147 $viewer = $this->getViewer(); 148 149 $datasource = $this->getDatasource() 150 ->setViewer($viewer); 151 152 $action = id(new PhabricatorEditEngineTokenizerCommentAction()) 153 ->setDatasource($datasource); 154 155 $limit = $this->getFieldConfigValue('limit'); 156 if ($limit) { 157 $action->setLimit($limit); 158 } 159 160 $value = $this->getFieldValue(); 161 if ($value !== null) { 162 $action->setInitialValue($value); 163 } 164 165 return $action; 166 } 167 168}