@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.

Partially support CustomFields in EditEngine

Summary:
Ref T9132. This isn't perfect, but doesn't break any existing functionality. This stuff works:

- Editing values.
- Reordering fields.
- All builtin field tyepes.

This stuff may not work yet:

- Assigning custom field defaults.
- Some conduit stuff.
- Fully custom fields?
- Locking/hiding fields? Didn't actually test this one.

I'll keep chipping away at that stuff. In some cases, it may be easier to convert all the CustomField apps first, although Differential might be a fair bit of work.

Test Plan:
Created a bunch of custom fields of every avialable type and edited them.

{F1008789}

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T9132

Differential Revision: https://secure.phabricator.com/D14617

+239 -15
+6
src/__phutil_library_map__.php
··· 1979 1979 'PhabricatorCustomFieldAttachment' => 'infrastructure/customfield/field/PhabricatorCustomFieldAttachment.php', 1980 1980 'PhabricatorCustomFieldConfigOptionType' => 'infrastructure/customfield/config/PhabricatorCustomFieldConfigOptionType.php', 1981 1981 'PhabricatorCustomFieldDataNotAvailableException' => 'infrastructure/customfield/exception/PhabricatorCustomFieldDataNotAvailableException.php', 1982 + 'PhabricatorCustomFieldEditEngineExtension' => 'infrastructure/customfield/editor/PhabricatorCustomFieldEditEngineExtension.php', 1983 + 'PhabricatorCustomFieldEditField' => 'infrastructure/customfield/editor/PhabricatorCustomFieldEditField.php', 1984 + 'PhabricatorCustomFieldEditType' => 'infrastructure/customfield/editor/PhabricatorCustomFieldEditType.php', 1982 1985 'PhabricatorCustomFieldHeraldField' => 'infrastructure/customfield/herald/PhabricatorCustomFieldHeraldField.php', 1983 1986 'PhabricatorCustomFieldHeraldFieldGroup' => 'infrastructure/customfield/herald/PhabricatorCustomFieldHeraldFieldGroup.php', 1984 1987 'PhabricatorCustomFieldImplementationIncompleteException' => 'infrastructure/customfield/exception/PhabricatorCustomFieldImplementationIncompleteException.php', ··· 6065 6068 'PhabricatorCustomFieldAttachment' => 'Phobject', 6066 6069 'PhabricatorCustomFieldConfigOptionType' => 'PhabricatorConfigOptionType', 6067 6070 'PhabricatorCustomFieldDataNotAvailableException' => 'Exception', 6071 + 'PhabricatorCustomFieldEditEngineExtension' => 'PhabricatorEditEngineExtension', 6072 + 'PhabricatorCustomFieldEditField' => 'PhabricatorEditField', 6073 + 'PhabricatorCustomFieldEditType' => 'PhabricatorEditType', 6068 6074 'PhabricatorCustomFieldHeraldField' => 'HeraldField', 6069 6075 'PhabricatorCustomFieldHeraldFieldGroup' => 'HeraldFieldGroup', 6070 6076 'PhabricatorCustomFieldImplementationIncompleteException' => 'Exception',
+23 -15
src/applications/transactions/editfield/PhabricatorEditField.php
··· 145 145 return $this->isHidden; 146 146 } 147 147 148 - protected function newControl() { 149 - throw new PhutilMethodNotImplementedException(); 150 - } 151 - 152 148 public function setIsSubmittedForm($is_submitted) { 153 149 $this->isSubmittedForm = $is_submitted; 154 150 return $this; ··· 176 172 return $this->controlError; 177 173 } 178 174 179 - protected function renderControl() { 175 + protected function newControl() { 176 + throw new PhutilMethodNotImplementedException(); 177 + } 178 + 179 + protected function buildControl() { 180 180 $control = $this->newControl(); 181 181 if ($control === null) { 182 182 return null; ··· 190 190 $control->setLabel($this->getLabel()); 191 191 } 192 192 193 + if ($this->getIsSubmittedForm()) { 194 + $error = $this->getControlError(); 195 + if ($error !== null) { 196 + $control->setError($error); 197 + } 198 + } else if ($this->getIsRequired()) { 199 + $control->setError(true); 200 + } 201 + 202 + return $control; 203 + } 204 + 205 + protected function renderControl() { 206 + $control = $this->buildControl(); 207 + if ($control === null) { 208 + return null; 209 + } 210 + 193 211 if ($this->getIsPreview()) { 194 212 $disabled = true; 195 213 $hidden = false; ··· 206 224 } 207 225 208 226 $control->setDisabled($disabled); 209 - 210 - 211 - if ($this->getIsSubmittedForm()) { 212 - $error = $this->getControlError(); 213 - if ($error !== null) { 214 - $control->setError($error); 215 - } 216 - } else if ($this->getIsRequired()) { 217 - $control->setError(true); 218 - } 219 227 220 228 return $control; 221 229 }
+50
src/infrastructure/customfield/editor/PhabricatorCustomFieldEditEngineExtension.php
··· 1 + <?php 2 + 3 + final class PhabricatorCustomFieldEditEngineExtension 4 + extends PhabricatorEditEngineExtension { 5 + 6 + const EXTENSIONKEY = 'customfield.fields'; 7 + 8 + public function getExtensionPriority() { 9 + return 5000; 10 + } 11 + 12 + public function isExtensionEnabled() { 13 + return true; 14 + } 15 + 16 + public function getExtensionName() { 17 + return pht('Custom Fields'); 18 + } 19 + 20 + public function supportsObject( 21 + PhabricatorEditEngine $engine, 22 + PhabricatorApplicationTransactionInterface $object) { 23 + return ($object instanceof PhabricatorCustomFieldInterface); 24 + } 25 + 26 + public function buildCustomEditFields( 27 + PhabricatorEditEngine $engine, 28 + PhabricatorApplicationTransactionInterface $object) { 29 + 30 + $viewer = $this->getViewer(); 31 + 32 + $field_list = PhabricatorCustomField::getObjectFields( 33 + $object, 34 + PhabricatorCustomField::ROLE_EDIT); 35 + 36 + $field_list->setViewer($viewer); 37 + $field_list->readFieldsFromStorage($object); 38 + 39 + $results = array(); 40 + foreach ($field_list->getFields() as $field) { 41 + $edit_fields = $field->getEditEngineFields($engine); 42 + foreach ($edit_fields as $edit_field) { 43 + $results[] = $edit_field; 44 + } 45 + } 46 + 47 + return $results; 48 + } 49 + 50 + }
+73
src/infrastructure/customfield/editor/PhabricatorCustomFieldEditField.php
··· 1 + <?php 2 + 3 + final class PhabricatorCustomFieldEditField 4 + extends PhabricatorEditField { 5 + 6 + private $customField; 7 + 8 + public function setCustomField(PhabricatorCustomField $custom_field) { 9 + $this->customField = $custom_field; 10 + return $this; 11 + } 12 + 13 + public function getCustomField() { 14 + return $this->customField; 15 + } 16 + 17 + protected function buildControl() { 18 + $field = $this->getCustomField(); 19 + $clone = clone $field; 20 + 21 + if ($this->getIsSubmittedForm()) { 22 + $value = $this->getValue(); 23 + $clone->setValueFromApplicationTransactions($value); 24 + } 25 + 26 + return $clone->renderEditControl(array()); 27 + } 28 + 29 + protected function newEditType() { 30 + return id(new PhabricatorCustomFieldEditType()) 31 + ->setCustomField($this->getCustomField()); 32 + } 33 + 34 + public function getValueForTransaction() { 35 + $value = $this->getValue(); 36 + $field = $this->getCustomField(); 37 + 38 + // Avoid changing the value of the field itself, since later calls would 39 + // incorrectly reflect the new value. 40 + $clone = clone $field; 41 + $clone->setValueFromApplicationTransactions($value); 42 + return $clone->getNewValueForApplicationTransactions(); 43 + } 44 + 45 + protected function getValueExistsInRequest(AphrontRequest $request, $key) { 46 + // For now, never read these out of the request. 47 + return false; 48 + } 49 + 50 + protected function getValueExistsInSubmit(AphrontRequest $request, $key) { 51 + return true; 52 + } 53 + 54 + protected function getValueFromSubmit(AphrontRequest $request, $key) { 55 + $field = $this->getCustomField(); 56 + 57 + $clone = clone $field; 58 + 59 + $clone->readValueFromRequest($request); 60 + return $clone->getNewValueForApplicationTransactions(); 61 + } 62 + 63 + public function getConduitEditTypes() { 64 + // TODO: For now, don't support custom fields over Conduit. 65 + return array(); 66 + } 67 + 68 + protected function newHTTPParameterType() { 69 + // TODO: For now, don't support custom fields for HTTP prefill. 70 + return null; 71 + } 72 + 73 + }
+53
src/infrastructure/customfield/editor/PhabricatorCustomFieldEditType.php
··· 1 + <?php 2 + 3 + final class PhabricatorCustomFieldEditType 4 + extends PhabricatorEditType { 5 + 6 + private $customField; 7 + 8 + public function setCustomField(PhabricatorCustomField $custom_field) { 9 + $this->customField = $custom_field; 10 + return $this; 11 + } 12 + 13 + public function getCustomField() { 14 + return $this->customField; 15 + } 16 + 17 + public function getValueType() { 18 + // TODO: Improve. 19 + return 'custom'; 20 + } 21 + 22 + public function getMetadata() { 23 + $field = $this->getCustomField(); 24 + return parent::getMetadata() + $field->getApplicationTransactionMetadata(); 25 + } 26 + 27 + public function getValueDescription() { 28 + $field = $this->getCustomField(); 29 + return $field->getFieldDescription(); 30 + } 31 + 32 + public function generateTransactions( 33 + PhabricatorApplicationTransaction $template, 34 + array $spec) { 35 + 36 + $value = idx($spec, 'value'); 37 + 38 + $xaction = $this->newTransaction($template) 39 + ->setNewValue($value); 40 + 41 + $custom_type = PhabricatorTransactions::TYPE_CUSTOMFIELD; 42 + if ($xaction->getTransactionType() == $custom_type) { 43 + $field = $this->getCustomField(); 44 + 45 + $xaction 46 + ->setOldValue($field->getOldValueForApplicationTransactions()) 47 + ->setMetadataValue('customfield:key', $field->getFieldKey()); 48 + } 49 + 50 + return array($xaction); 51 + } 52 + 53 + }
+27
src/infrastructure/customfield/field/PhabricatorCustomField.php
··· 1082 1082 /* -( Edit View )---------------------------------------------------------- */ 1083 1083 1084 1084 1085 + public function getEditEngineFields(PhabricatorEditEngine $engine) { 1086 + $field = $this->newStandardEditField($engine); 1087 + 1088 + return array( 1089 + $field, 1090 + ); 1091 + } 1092 + 1093 + protected function newEditField() { 1094 + return id(new PhabricatorCustomFieldEditField()) 1095 + ->setCustomField($this); 1096 + } 1097 + 1098 + protected function newStandardEditField() { 1099 + if ($this->proxy) { 1100 + return $this->proxy->newStandardEditField(); 1101 + } 1102 + 1103 + return $this->newEditField() 1104 + ->setKey($this->getFieldKey()) 1105 + ->setEditTypeKey('custom.'.$this->getFieldKey()) 1106 + ->setLabel($this->getFieldName()) 1107 + ->setDescription($this->getFieldDescription()) 1108 + ->setTransactionType($this->getApplicationTransactionType()) 1109 + ->setValue($this->getNewValueForApplicationTransactions()); 1110 + } 1111 + 1085 1112 /** 1086 1113 * @task edit 1087 1114 */
+7
src/infrastructure/customfield/standard/PhabricatorStandardCustomField.php
··· 426 426 } 427 427 } 428 428 429 + protected function newStandardEditField() { 430 + $short = 'custom.'.$this->getRawStandardFieldKey(); 431 + 432 + return parent::newStandardEditField() 433 + ->setEditTypeKey($short); 434 + } 435 + 429 436 }