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

Allow users to unset "Editor", tailor short error messages properly on settings forms

Summary:
Ref T11098.

- Allow "Editor" to be set to the empty string.
- Don't match a validation error to a field unless the actual settings for the field and error match.

Test Plan:
- Tried to set "Editor" to "", success.
- Tried to set "Editor" to "javascript://", only that field got marked "Invalid".

Reviewers: avivey, chad

Reviewed By: chad

Maniphest Tasks: T11098

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

+57 -7
+39
src/applications/settings/editor/PhabricatorSettingsEditEngine.php
··· 194 194 return $fields; 195 195 } 196 196 197 + protected function getValidationExceptionShortMessage( 198 + PhabricatorApplicationTransactionValidationException $ex, 199 + PhabricatorEditField $field) { 200 + 201 + // Settings fields all have the same transaction type so we need to make 202 + // sure the transaction is changing the same setting before matching an 203 + // error to a given field. 204 + $xaction_type = $field->getTransactionType(); 205 + if ($xaction_type == PhabricatorUserPreferencesTransaction::TYPE_SETTING) { 206 + $property = PhabricatorUserPreferencesTransaction::PROPERTY_SETTING; 207 + 208 + $field_setting = idx($field->getMetadata(), $property); 209 + foreach ($ex->getErrors() as $error) { 210 + if ($error->getType() !== $xaction_type) { 211 + continue; 212 + } 213 + 214 + $xaction = $error->getTransaction(); 215 + if (!$xaction) { 216 + continue; 217 + } 218 + 219 + $xaction_setting = $xaction->getMetadataValue($property); 220 + if ($xaction_setting != $field_setting) { 221 + continue; 222 + } 223 + 224 + $short_message = $error->getShortMessage(); 225 + if ($short_message !== null) { 226 + return $short_message; 227 + } 228 + } 229 + 230 + return null; 231 + } 232 + 233 + return parent::getValidationExceptionShortMessage($ex, $field); 234 + } 235 + 197 236 }
+4
src/applications/settings/setting/PhabricatorEditorSetting.php
··· 39 39 } 40 40 41 41 public function validateTransactionValue($value) { 42 + if (!strlen($value)) { 43 + return; 44 + } 45 + 42 46 $ok = PhabricatorHelpEditorProtocolController::hasAllowedProtocol($value); 43 47 if ($ok) { 44 48 return;
+13 -6
src/applications/transactions/editengine/PhabricatorEditEngine.php
··· 1004 1004 $validation_exception = $ex; 1005 1005 1006 1006 foreach ($fields as $field) { 1007 - $xaction_type = $field->getTransactionType(); 1008 - if ($xaction_type === null) { 1009 - continue; 1010 - } 1011 - 1012 - $message = $ex->getShortMessage($xaction_type); 1007 + $message = $this->getValidationExceptionShortMessage($ex, $field); 1013 1008 if ($message === null) { 1014 1009 continue; 1015 1010 } ··· 2047 2042 ->setName($item_name) 2048 2043 ->setIcon($item_icon) 2049 2044 ->setHref($item_uri); 2045 + } 2046 + 2047 + protected function getValidationExceptionShortMessage( 2048 + PhabricatorApplicationTransactionValidationException $ex, 2049 + PhabricatorEditField $field) { 2050 + 2051 + $xaction_type = $field->getTransactionType(); 2052 + if ($xaction_type === null) { 2053 + return null; 2054 + } 2055 + 2056 + return $ex->getShortMessage($xaction_type); 2050 2057 } 2051 2058 2052 2059 protected function getCreateNewObjectPolicy() {
+1 -1
src/applications/transactions/error/PhabricatorApplicationTransactionValidationError.php
··· 26 26 } 27 27 28 28 public function getTransaction() { 29 - return $this->tranaction; 29 + return $this->transaction; 30 30 } 31 31 32 32 public function getShortMessage() {