Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15397885
D14634.id35404.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
16 KB
Referenced Files
None
Subscribers
None
D14634.id35404.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
@@ -103,6 +103,7 @@
'AphrontAjaxResponse' => 'aphront/response/AphrontAjaxResponse.php',
'AphrontApplicationConfiguration' => 'aphront/configuration/AphrontApplicationConfiguration.php',
'AphrontBarView' => 'view/widget/bars/AphrontBarView.php',
+ 'AphrontBoolHTTPParameterType' => 'aphront/httpparametertype/AphrontBoolHTTPParameterType.php',
'AphrontCSRFException' => 'aphront/exception/AphrontCSRFException.php',
'AphrontCalendarEventView' => 'applications/calendar/view/AphrontCalendarEventView.php',
'AphrontController' => 'aphront/AphrontController.php',
@@ -139,6 +140,7 @@
'AphrontHTTPProxyResponse' => 'aphront/response/AphrontHTTPProxyResponse.php',
'AphrontHTTPSink' => 'aphront/sink/AphrontHTTPSink.php',
'AphrontHTTPSinkTestCase' => 'aphront/sink/__tests__/AphrontHTTPSinkTestCase.php',
+ 'AphrontIntHTTPParameterType' => 'aphront/httpparametertype/AphrontIntHTTPParameterType.php',
'AphrontIsolatedDatabaseConnectionTestCase' => 'infrastructure/storage/__tests__/AphrontIsolatedDatabaseConnectionTestCase.php',
'AphrontIsolatedHTTPSink' => 'aphront/sink/AphrontIsolatedHTTPSink.php',
'AphrontJSONResponse' => 'aphront/response/AphrontJSONResponse.php',
@@ -3907,6 +3909,7 @@
'AphrontAjaxResponse' => 'AphrontResponse',
'AphrontApplicationConfiguration' => 'Phobject',
'AphrontBarView' => 'AphrontView',
+ 'AphrontBoolHTTPParameterType' => 'AphrontHTTPParameterType',
'AphrontCSRFException' => 'AphrontException',
'AphrontCalendarEventView' => 'AphrontView',
'AphrontController' => 'Phobject',
@@ -3946,6 +3949,7 @@
'AphrontHTTPProxyResponse' => 'AphrontResponse',
'AphrontHTTPSink' => 'Phobject',
'AphrontHTTPSinkTestCase' => 'PhabricatorTestCase',
+ 'AphrontIntHTTPParameterType' => 'AphrontHTTPParameterType',
'AphrontIsolatedDatabaseConnectionTestCase' => 'PhabricatorTestCase',
'AphrontIsolatedHTTPSink' => 'AphrontHTTPSink',
'AphrontJSONResponse' => 'AphrontResponse',
diff --git a/src/aphront/httpparametertype/AphrontBoolHTTPParameterType.php b/src/aphront/httpparametertype/AphrontBoolHTTPParameterType.php
new file mode 100644
--- /dev/null
+++ b/src/aphront/httpparametertype/AphrontBoolHTTPParameterType.php
@@ -0,0 +1,29 @@
+<?php
+
+final class AphrontBoolHTTPParameterType
+ extends AphrontHTTPParameterType {
+
+ protected function getParameterValue(AphrontRequest $request, $key) {
+ return $request->getBool($key);
+ }
+
+ protected function getParameterTypeName() {
+ return 'bool';
+ }
+
+ protected function getParameterFormatDescriptions() {
+ return array(
+ pht('A boolean value (true or false).'),
+ );
+ }
+
+ protected function getParameterExamples() {
+ return array(
+ 'v=true',
+ 'v=false',
+ 'v=1',
+ 'v=0',
+ );
+ }
+
+}
diff --git a/src/aphront/httpparametertype/AphrontIntHTTPParameterType.php b/src/aphront/httpparametertype/AphrontIntHTTPParameterType.php
new file mode 100644
--- /dev/null
+++ b/src/aphront/httpparametertype/AphrontIntHTTPParameterType.php
@@ -0,0 +1,26 @@
+<?php
+
+final class AphrontIntHTTPParameterType
+ extends AphrontHTTPParameterType {
+
+ protected function getParameterValue(AphrontRequest $request, $key) {
+ return $request->getInt($key);
+ }
+
+ protected function getParameterTypeName() {
+ return 'int';
+ }
+
+ protected function getParameterFormatDescriptions() {
+ return array(
+ pht('An integer.'),
+ );
+ }
+
+ protected function getParameterExamples() {
+ return array(
+ 'v=123',
+ );
+ }
+
+}
diff --git a/src/applications/transactions/editengine/PhabricatorEditEngine.php b/src/applications/transactions/editengine/PhabricatorEditEngine.php
--- a/src/applications/transactions/editengine/PhabricatorEditEngine.php
+++ b/src/applications/transactions/editengine/PhabricatorEditEngine.php
@@ -685,10 +685,6 @@
$field->readValueFromRequest($request);
}
- } else {
- foreach ($fields as $field) {
- $field->readValueFromObject($object);
- }
}
}
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
@@ -299,24 +299,27 @@
}
public function readValueFromRequest(AphrontRequest $request) {
- $check = array_merge(array($this->getKey()), $this->getAliases());
+ $check = $this->getAllReadValueFromRequestKeys();
foreach ($check as $key) {
if (!$this->getValueExistsInRequest($request, $key)) {
continue;
}
$this->value = $this->getValueFromRequest($request, $key);
- return;
+ break;
}
-
- $this->readValueFromObject($this->getObject());
-
return $this;
}
- public function readValueFromObject($object) {
- $this->value = $this->getValueFromObject($object);
- return $this;
+ public function getAllReadValueFromRequestKeys() {
+ $keys = array();
+
+ $keys[] = $this->getKey();
+ foreach ($this->getAliases() as $alias) {
+ $keys[] = $alias;
+ }
+
+ return $keys;
}
public function readDefaultValueFromConfiguration($value) {
@@ -337,11 +340,11 @@
}
protected function getValueExistsInRequest(AphrontRequest $request, $key) {
- return $this->getValueExistsInSubmit($request, $key);
+ return $this->getHTTPParameterValueExists($request, $key);
}
protected function getValueFromRequest(AphrontRequest $request, $key) {
- return $this->getValueFromSubmit($request, $key);
+ return $this->getHTTPParameterValue($request, $key);
}
@@ -385,6 +388,16 @@
}
protected function getValueExistsInSubmit(AphrontRequest $request, $key) {
+ return $this->getHTTPParameterValueExists($request, $key);
+ }
+
+ protected function getValueFromSubmit(AphrontRequest $request, $key) {
+ return $this->getHTTPParameterValue($request, $key);
+ }
+
+ protected function getHTTPParameterValueExists(
+ AphrontRequest $request,
+ $key) {
$type = $this->getHTTPParameterType();
if ($type) {
@@ -394,8 +407,14 @@
return false;
}
- protected function getValueFromSubmit(AphrontRequest $request, $key) {
- return $this->getHTTPParameterType()->getValue($request, $key);
+ protected function getHTTPParameterValue($request, $key) {
+ $type = $this->getHTTPParameterType();
+
+ if ($type) {
+ return $type->getValue($request, $key);
+ }
+
+ return null;
}
protected function getDefaultValue() {
diff --git a/src/applications/transactions/view/PhabricatorApplicationEditHTTPParameterHelpView.php b/src/applications/transactions/view/PhabricatorApplicationEditHTTPParameterHelpView.php
--- a/src/applications/transactions/view/PhabricatorApplicationEditHTTPParameterHelpView.php
+++ b/src/applications/transactions/view/PhabricatorApplicationEditHTTPParameterHelpView.php
@@ -95,7 +95,7 @@
foreach ($fields as $field) {
$rows[] = array(
$field->getLabel(),
- $field->getKey(),
+ head($field->getAllReadValueFromRequestKeys()),
$field->getHTTPParameterType()->getTypeName(),
$field->getDescription(),
);
@@ -150,7 +150,7 @@
$rows = array();
foreach ($fields as $field) {
- $aliases = $field->getAliases();
+ $aliases = array_slice($field->getAllReadValueFromRequestKeys(), 1);
if (!$aliases) {
continue;
}
diff --git a/src/infrastructure/customfield/editor/PhabricatorCustomFieldEditEngineExtension.php b/src/infrastructure/customfield/editor/PhabricatorCustomFieldEditEngineExtension.php
--- a/src/infrastructure/customfield/editor/PhabricatorCustomFieldEditEngineExtension.php
+++ b/src/infrastructure/customfield/editor/PhabricatorCustomFieldEditEngineExtension.php
@@ -34,7 +34,10 @@
PhabricatorCustomField::ROLE_EDIT);
$field_list->setViewer($viewer);
- $field_list->readFieldsFromStorage($object);
+
+ if (!$engine->getIsCreate()) {
+ $field_list->readFieldsFromStorage($object);
+ }
$results = array();
foreach ($field_list->getFields() as $field) {
diff --git a/src/infrastructure/customfield/editor/PhabricatorCustomFieldEditField.php b/src/infrastructure/customfield/editor/PhabricatorCustomFieldEditField.php
--- a/src/infrastructure/customfield/editor/PhabricatorCustomFieldEditField.php
+++ b/src/infrastructure/customfield/editor/PhabricatorCustomFieldEditField.php
@@ -4,6 +4,7 @@
extends PhabricatorEditField {
private $customField;
+ private $httpParameterType;
public function setCustomField(PhabricatorCustomField $custom_field) {
$this->customField = $custom_field;
@@ -14,14 +15,22 @@
return $this->customField;
}
+ public function setCustomFieldHTTPParameterType(
+ AphrontHTTPParameterType $type) {
+ $this->httpParameterType = $type;
+ return $this;
+ }
+
+ public function getCustomFieldHTTPParameterType() {
+ return $this->httpParameterType;
+ }
+
protected function buildControl() {
$field = $this->getCustomField();
$clone = clone $field;
- if ($this->getIsSubmittedForm()) {
- $value = $this->getValue();
- $clone->setValueFromApplicationTransactions($value);
- }
+ $value = $this->getValue();
+ $clone->setValueFromApplicationTransactions($value);
return $clone->renderEditControl(array());
}
@@ -42,11 +51,6 @@
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;
}
@@ -66,8 +70,31 @@
}
protected function newHTTPParameterType() {
- // TODO: For now, don't support custom fields for HTTP prefill.
+ $type = $this->getCustomFieldHTTPParameterType();
+
+ if ($type) {
+ return clone $type;
+ }
+
return null;
}
+ public function getAllReadValueFromRequestKeys() {
+ $keys = array();
+
+ // NOTE: This piece of complexity is so we can expose a reasonable key in
+ // the UI ("custom.x") instead of a crufty internal key ("std:app:x").
+ // Perhaps we can simplify this some day.
+
+ // In the parent, this is just getKey(), but that returns a cumbersome
+ // key in EditFields. Use the simpler edit type key instead.
+ $keys[] = $this->getEditTypeKey();
+
+ foreach ($this->getAliases() as $alias) {
+ $keys[] = $alias;
+ }
+
+ return $keys;
+ }
+
}
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
@@ -1091,8 +1091,15 @@
}
protected function newEditField() {
- return id(new PhabricatorCustomFieldEditField())
+ $field = id(new PhabricatorCustomFieldEditField())
->setCustomField($this);
+
+ $http_type = $this->getHTTPParameterType();
+ if ($http_type) {
+ $field->setCustomFieldHTTPParameterType($http_type);
+ }
+
+ return $field;
}
protected function newStandardEditField() {
@@ -1109,6 +1116,13 @@
->setValue($this->getNewValueForApplicationTransactions());
}
+ protected function getHTTPParameterType() {
+ if ($this->proxy) {
+ return $this->proxy->getHTTPParameterType();
+ }
+ return null;
+ }
+
/**
* @task edit
*/
diff --git a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldBool.php b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldBool.php
--- a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldBool.php
+++ b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldBool.php
@@ -129,4 +129,8 @@
);
}
+ protected function getHTTPParameterType() {
+ return new AphrontBoolHTTPParameterType();
+ }
+
}
diff --git a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldInt.php b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldInt.php
--- a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldInt.php
+++ b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldInt.php
@@ -112,5 +112,9 @@
}
}
+ protected function getHTTPParameterType() {
+ return new AphrontIntHTTPParameterType();
+ }
+
}
diff --git a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldLink.php b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldLink.php
--- a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldLink.php
+++ b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldLink.php
@@ -80,4 +80,8 @@
);
}
+ protected function getHTTPParameterType() {
+ return new AphrontStringHTTPParameterType();
+ }
+
}
diff --git a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldPHIDs.php b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldPHIDs.php
--- a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldPHIDs.php
+++ b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldPHIDs.php
@@ -34,14 +34,21 @@
}
public function setValueFromStorage($value) {
+ // NOTE: We're accepting either a JSON string (a real storage value) or
+ // an array (from HTTP parameter prefilling). This is a little hacky, but
+ // should hold until this can get cleaned up more thoroughly.
+ // TODO: Clean this up.
+
$result = array();
- if ($value) {
+ if (!is_array($value)) {
$value = json_decode($value, true);
if (is_array($value)) {
$result = array_values($value);
}
}
+
$this->setFieldValue($value);
+
return $this;
}
@@ -213,4 +220,8 @@
return $value;
}
+ protected function getHTTPParameterType() {
+ return new AphrontPHIDListHTTPParameterType();
+ }
+
}
diff --git a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldRemarkup.php b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldRemarkup.php
--- a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldRemarkup.php
+++ b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldRemarkup.php
@@ -95,5 +95,9 @@
);
}
+ protected function getHTTPParameterType() {
+ return new AphrontStringHTTPParameterType();
+ }
+
}
diff --git a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldSelect.php b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldSelect.php
--- a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldSelect.php
+++ b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldSelect.php
@@ -136,4 +136,8 @@
->setValueMap($this->getOptions());
}
+ protected function getHTTPParameterType() {
+ return new AphrontSelectHTTPParameterType();
+ }
+
}
diff --git a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldText.php b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldText.php
--- a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldText.php
+++ b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldText.php
@@ -63,4 +63,8 @@
);
}
+ protected function getHTTPParameterType() {
+ return new AphrontStringHTTPParameterType();
+ }
+
}
diff --git a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldUsers.php b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldUsers.php
--- a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldUsers.php
+++ b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldUsers.php
@@ -11,4 +11,8 @@
return new PhabricatorPeopleDatasource();
}
+ protected function getHTTPParameterType() {
+ return new AphrontUserListHTTPParameterType();
+ }
+
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Mar 17, 10:47 PM (3 w, 5 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7708989
Default Alt Text
D14634.id35404.diff (16 KB)
Attached To
Mode
D14634: Support HTTP parameter prefilling in EditEngine forms for CustomFields
Attached
Detach File
Event Timeline
Log In to Comment