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

Improve the behavior of PhabricatorFileEditField for Macros

Summary:
See D17848. This improves things a little bit in two cases:

Case 1:

- Create a macro.
- Pick a valid file.
- Pick an invalid name.
- Submit form.
- Before patch: your file is lost and you have to pick it again.
- After patch: your file is "held" in the form, you just can't see it in the UI. If you submit again, it keeps the same file. If you pick a new file, it uses that one instead.

Case 2:

- Apply D17848.
- Delete the `if ($value) {` thing that I'm weirded out about (see inline).
- Edit a macro.
- Don't pick a new file.
- Before patch: error, can't null the image PHID.
- Afer patch: not picking a new file means "keep the same file", but you can't tell from the UI.

Basically, the behaviors are good now, they just aren't very clear from the UI since "the field has an existing/just-submitted value" and "the field is empty" look the same. I think this is still a net win and we can fix up the UI later.

Test Plan: See workflows above.

Reviewers: chad

Reviewed By: chad

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

+51 -11
+10 -2
src/aphront/httpparametertype/AphrontFileHTTPParameterType.php
··· 7 7 return $key.'_raw'; 8 8 } 9 9 10 + private function getDefaultKey($key) { 11 + return $key.'_default'; 12 + } 13 + 10 14 protected function getParameterExists(AphrontRequest $request, $key) { 11 15 $file_key = $this->getFileKey($key); 16 + $default_key = $this->getDefaultKey($key); 17 + 12 18 return $request->getExists($key) || 13 - $request->getFileExists($file_key); 19 + $request->getFileExists($file_key) || 20 + $request->getExists($default_key); 14 21 } 15 22 16 23 protected function getParameterValue(AphrontRequest $request, $key) { ··· 27 34 // this code around as a fallback if the client-side JS goes awry. 28 35 29 36 $file_key = $this->getFileKey($key); 37 + $default_key = $this->getDefaultKey($key); 30 38 if (!$request->getFileExists($file_key)) { 31 - return null; 39 + return $request->getStr($default_key); 32 40 } 33 41 34 42 $viewer = $this->getViewer();
+41 -9
src/view/form/control/PHUIFormFileControl.php
··· 30 30 'chunkThreshold' => PhabricatorFileStorageEngine::getChunkThreshold(), 31 31 )); 32 32 33 - return phutil_tag( 34 - 'input', 35 - array( 36 - 'type' => 'file', 37 - 'multiple' => $this->getAllowMultiple() ? 'multiple' : null, 38 - 'name' => $this->getName().'.raw', 39 - 'id' => $file_id, 40 - 'disabled' => $this->getDisabled() ? 'disabled' : null, 41 - )); 33 + 34 + // If the control has a value, add a hidden input which submits it as a 35 + // default. This allows the file control to mean "don't change anything", 36 + // instead of "remove the file", if the user submits the form without 37 + // touching it. 38 + 39 + // This also allows the input to "hold" the value of an uploaded file if 40 + // there is another error in the form: when you submit the form but are 41 + // stopped because of an unrelated error, submitting it again will keep 42 + // the value around (if you don't upload a new file) instead of requiring 43 + // you to pick the file again. 44 + 45 + // TODO: This works alright, but is a bit of a hack, and the UI should 46 + // provide the user better feedback about whether the state of the control 47 + // is "keep the value the same" or "remove the value", and about whether 48 + // or not the control is "holding" a value from a previous submission. 49 + 50 + $default_input = null; 51 + $default_value = $this->getValue(); 52 + if ($default_value !== null) { 53 + $default_input = phutil_tag( 54 + 'input', 55 + array( 56 + 'type' => 'hidden', 57 + 'name' => $this->getName().'_default', 58 + 'value' => $default_value, 59 + )); 60 + } 61 + 62 + return array( 63 + phutil_tag( 64 + 'input', 65 + array( 66 + 'type' => 'file', 67 + 'multiple' => $this->getAllowMultiple() ? 'multiple' : null, 68 + 'name' => $this->getName().'_raw', 69 + 'id' => $file_id, 70 + 'disabled' => $this->getDisabled() ? 'disabled' : null, 71 + )), 72 + $default_input, 73 + ); 42 74 } 43 75 44 76 }