Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14762154
D14617.id35401.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
10 KB
Referenced Files
None
Subscribers
None
D14617.id35401.diff
View Options
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -1979,6 +1979,9 @@
'PhabricatorCustomFieldAttachment' => 'infrastructure/customfield/field/PhabricatorCustomFieldAttachment.php',
'PhabricatorCustomFieldConfigOptionType' => 'infrastructure/customfield/config/PhabricatorCustomFieldConfigOptionType.php',
'PhabricatorCustomFieldDataNotAvailableException' => 'infrastructure/customfield/exception/PhabricatorCustomFieldDataNotAvailableException.php',
+ 'PhabricatorCustomFieldEditEngineExtension' => 'infrastructure/customfield/editor/PhabricatorCustomFieldEditEngineExtension.php',
+ 'PhabricatorCustomFieldEditField' => 'infrastructure/customfield/editor/PhabricatorCustomFieldEditField.php',
+ 'PhabricatorCustomFieldEditType' => 'infrastructure/customfield/editor/PhabricatorCustomFieldEditType.php',
'PhabricatorCustomFieldHeraldField' => 'infrastructure/customfield/herald/PhabricatorCustomFieldHeraldField.php',
'PhabricatorCustomFieldHeraldFieldGroup' => 'infrastructure/customfield/herald/PhabricatorCustomFieldHeraldFieldGroup.php',
'PhabricatorCustomFieldImplementationIncompleteException' => 'infrastructure/customfield/exception/PhabricatorCustomFieldImplementationIncompleteException.php',
@@ -6063,6 +6066,9 @@
'PhabricatorCustomFieldAttachment' => 'Phobject',
'PhabricatorCustomFieldConfigOptionType' => 'PhabricatorConfigOptionType',
'PhabricatorCustomFieldDataNotAvailableException' => 'Exception',
+ 'PhabricatorCustomFieldEditEngineExtension' => 'PhabricatorEditEngineExtension',
+ 'PhabricatorCustomFieldEditField' => 'PhabricatorEditField',
+ 'PhabricatorCustomFieldEditType' => 'PhabricatorEditType',
'PhabricatorCustomFieldHeraldField' => 'HeraldField',
'PhabricatorCustomFieldHeraldFieldGroup' => 'HeraldFieldGroup',
'PhabricatorCustomFieldImplementationIncompleteException' => 'Exception',
diff --git a/src/applications/transactions/editfield/PhabricatorEditField.php b/src/applications/transactions/editfield/PhabricatorEditField.php
--- a/src/applications/transactions/editfield/PhabricatorEditField.php
+++ b/src/applications/transactions/editfield/PhabricatorEditField.php
@@ -145,10 +145,6 @@
return $this->isHidden;
}
- protected function newControl() {
- throw new PhutilMethodNotImplementedException();
- }
-
public function setIsSubmittedForm($is_submitted) {
$this->isSubmittedForm = $is_submitted;
return $this;
@@ -176,7 +172,11 @@
return $this->controlError;
}
- protected function renderControl() {
+ protected function newControl() {
+ throw new PhutilMethodNotImplementedException();
+ }
+
+ protected function buildControl() {
$control = $this->newControl();
if ($control === null) {
return null;
@@ -190,6 +190,24 @@
$control->setLabel($this->getLabel());
}
+ if ($this->getIsSubmittedForm()) {
+ $error = $this->getControlError();
+ if ($error !== null) {
+ $control->setError($error);
+ }
+ } else if ($this->getIsRequired()) {
+ $control->setError(true);
+ }
+
+ return $control;
+ }
+
+ protected function renderControl() {
+ $control = $this->buildControl();
+ if ($control === null) {
+ return null;
+ }
+
if ($this->getIsPreview()) {
$disabled = true;
$hidden = false;
@@ -207,16 +225,6 @@
$control->setDisabled($disabled);
-
- if ($this->getIsSubmittedForm()) {
- $error = $this->getControlError();
- if ($error !== null) {
- $control->setError($error);
- }
- } else if ($this->getIsRequired()) {
- $control->setError(true);
- }
-
return $control;
}
diff --git a/src/infrastructure/customfield/editor/PhabricatorCustomFieldEditEngineExtension.php b/src/infrastructure/customfield/editor/PhabricatorCustomFieldEditEngineExtension.php
new file mode 100644
--- /dev/null
+++ b/src/infrastructure/customfield/editor/PhabricatorCustomFieldEditEngineExtension.php
@@ -0,0 +1,50 @@
+<?php
+
+final class PhabricatorCustomFieldEditEngineExtension
+ extends PhabricatorEditEngineExtension {
+
+ const EXTENSIONKEY = 'customfield.fields';
+
+ public function getExtensionPriority() {
+ return 5000;
+ }
+
+ public function isExtensionEnabled() {
+ return true;
+ }
+
+ public function getExtensionName() {
+ return pht('Custom Fields');
+ }
+
+ public function supportsObject(
+ PhabricatorEditEngine $engine,
+ PhabricatorApplicationTransactionInterface $object) {
+ return ($object instanceof PhabricatorCustomFieldInterface);
+ }
+
+ public function buildCustomEditFields(
+ PhabricatorEditEngine $engine,
+ PhabricatorApplicationTransactionInterface $object) {
+
+ $viewer = $this->getViewer();
+
+ $field_list = PhabricatorCustomField::getObjectFields(
+ $object,
+ PhabricatorCustomField::ROLE_EDIT);
+
+ $field_list->setViewer($viewer);
+ $field_list->readFieldsFromStorage($object);
+
+ $results = array();
+ foreach ($field_list->getFields() as $field) {
+ $edit_fields = $field->getEditEngineFields($engine);
+ foreach ($edit_fields as $edit_field) {
+ $results[] = $edit_field;
+ }
+ }
+
+ return $results;
+ }
+
+}
diff --git a/src/infrastructure/customfield/editor/PhabricatorCustomFieldEditField.php b/src/infrastructure/customfield/editor/PhabricatorCustomFieldEditField.php
new file mode 100644
--- /dev/null
+++ b/src/infrastructure/customfield/editor/PhabricatorCustomFieldEditField.php
@@ -0,0 +1,73 @@
+<?php
+
+final class PhabricatorCustomFieldEditField
+ extends PhabricatorEditField {
+
+ private $customField;
+
+ public function setCustomField(PhabricatorCustomField $custom_field) {
+ $this->customField = $custom_field;
+ return $this;
+ }
+
+ public function getCustomField() {
+ return $this->customField;
+ }
+
+ protected function buildControl() {
+ $field = $this->getCustomField();
+ $clone = clone $field;
+
+ if ($this->getIsSubmittedForm()) {
+ $value = $this->getValue();
+ $clone->setValueFromApplicationTransactions($value);
+ }
+
+ return $clone->renderEditControl(array());
+ }
+
+ protected function newEditType() {
+ return id(new PhabricatorCustomFieldEditType())
+ ->setCustomField($this->getCustomField());
+ }
+
+ public function getValueForTransaction() {
+ $value = $this->getValue();
+ $field = $this->getCustomField();
+
+ // Avoid changing the value of the field itself, since later calls would
+ // incorrectly reflect the new value.
+ $clone = clone $field;
+ $clone->setValueFromApplicationTransactions($value);
+ return $clone->getNewValueForApplicationTransactions();
+ }
+
+ protected function getValueExistsInRequest(AphrontRequest $request, $key) {
+ // For now, never read these out of the request.
+ return false;
+ }
+
+ protected function getValueExistsInSubmit(AphrontRequest $request, $key) {
+ return true;
+ }
+
+ protected function getValueFromSubmit(AphrontRequest $request, $key) {
+ $field = $this->getCustomField();
+
+ $clone = clone $field;
+
+ $clone->readValueFromRequest($request);
+ return $clone->getNewValueForApplicationTransactions();
+ }
+
+ public function getConduitEditTypes() {
+ // TODO: For now, don't support custom fields over Conduit.
+ return array();
+ }
+
+ protected function newHTTPParameterType() {
+ // TODO: For now, don't support custom fields for HTTP prefill.
+ return null;
+ }
+
+}
diff --git a/src/infrastructure/customfield/editor/PhabricatorCustomFieldEditType.php b/src/infrastructure/customfield/editor/PhabricatorCustomFieldEditType.php
new file mode 100644
--- /dev/null
+++ b/src/infrastructure/customfield/editor/PhabricatorCustomFieldEditType.php
@@ -0,0 +1,53 @@
+<?php
+
+final class PhabricatorCustomFieldEditType
+ extends PhabricatorEditType {
+
+ private $customField;
+
+ public function setCustomField(PhabricatorCustomField $custom_field) {
+ $this->customField = $custom_field;
+ return $this;
+ }
+
+ public function getCustomField() {
+ return $this->customField;
+ }
+
+ public function getValueType() {
+ // TODO: Improve.
+ return 'custom';
+ }
+
+ public function getMetadata() {
+ $field = $this->getCustomField();
+ return parent::getMetadata() + $field->getApplicationTransactionMetadata();
+ }
+
+ public function getValueDescription() {
+ $field = $this->getCustomField();
+ return $field->getFieldDescription();
+ }
+
+ public function generateTransactions(
+ PhabricatorApplicationTransaction $template,
+ array $spec) {
+
+ $value = idx($spec, 'value');
+
+ $xaction = $this->newTransaction($template)
+ ->setNewValue($value);
+
+ $custom_type = PhabricatorTransactions::TYPE_CUSTOMFIELD;
+ if ($xaction->getTransactionType() == $custom_type) {
+ $field = $this->getCustomField();
+
+ $xaction
+ ->setOldValue($field->getOldValueForApplicationTransactions())
+ ->setMetadataValue('customfield:key', $field->getFieldKey());
+ }
+
+ return array($xaction);
+ }
+
+}
diff --git a/src/infrastructure/customfield/field/PhabricatorCustomField.php b/src/infrastructure/customfield/field/PhabricatorCustomField.php
--- a/src/infrastructure/customfield/field/PhabricatorCustomField.php
+++ b/src/infrastructure/customfield/field/PhabricatorCustomField.php
@@ -1082,6 +1082,33 @@
/* -( Edit View )---------------------------------------------------------- */
+ public function getEditEngineFields(PhabricatorEditEngine $engine) {
+ $field = $this->newStandardEditField($engine);
+
+ return array(
+ $field,
+ );
+ }
+
+ protected function newEditField() {
+ return id(new PhabricatorCustomFieldEditField())
+ ->setCustomField($this);
+ }
+
+ protected function newStandardEditField() {
+ if ($this->proxy) {
+ return $this->proxy->newStandardEditField();
+ }
+
+ return $this->newEditField()
+ ->setKey($this->getFieldKey())
+ ->setEditTypeKey('custom.'.$this->getFieldKey())
+ ->setLabel($this->getFieldName())
+ ->setDescription($this->getFieldDescription())
+ ->setTransactionType($this->getApplicationTransactionType())
+ ->setValue($this->getNewValueForApplicationTransactions());
+ }
+
/**
* @task edit
*/
diff --git a/src/infrastructure/customfield/standard/PhabricatorStandardCustomField.php b/src/infrastructure/customfield/standard/PhabricatorStandardCustomField.php
--- a/src/infrastructure/customfield/standard/PhabricatorStandardCustomField.php
+++ b/src/infrastructure/customfield/standard/PhabricatorStandardCustomField.php
@@ -426,4 +426,11 @@
}
}
+ protected function newStandardEditField() {
+ $short = 'custom.'.$this->getRawStandardFieldKey();
+
+ return parent::newStandardEditField()
+ ->setEditTypeKey($short);
+ }
+
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Jan 24, 4:54 AM (8 h, 59 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7036597
Default Alt Text
D14617.id35401.diff (10 KB)
Attached To
Mode
D14617: Partially support CustomFields in EditEngine
Attached
Detach File
Event Timeline
Log In to Comment