From a9aedc64e4791a65779e5587492d6bcb528af03a Mon Sep 17 00:00:00 2001 From: Ricky Elrod Date: Fri, 28 Dec 2012 11:37:55 -0800 Subject: [PATCH] Show the default value in Config. Summary: As mentioned by @epriestley in an inline on D4290, we should show what happens if the user leaves the box blank. Test Plan: Went to edit a setting and saw the default below the text box. Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin, asherkin Differential Revision: https://secure.phabricator.com/D4293 --- .../PhabricatorConfigController.php | 16 ++++++++++ .../PhabricatorConfigEditController.php | 30 ++++++++++++------- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/src/applications/config/controller/PhabricatorConfigController.php b/src/applications/config/controller/PhabricatorConfigController.php index a94cb7fe4c..01197efa5c 100644 --- a/src/applications/config/controller/PhabricatorConfigController.php +++ b/src/applications/config/controller/PhabricatorConfigController.php @@ -24,4 +24,20 @@ abstract class PhabricatorConfigController extends PhabricatorController { return $crumbs; } + /** + * Properly format a JSON value. + * + * @param wild Any value, but should be a raw value, not a string of JSON. + * @return string + */ + public function prettyPrintJSON($value) { + // Check not only that it's an array, but that it's an "unnatural" array + // meaning that the keys aren't 0 -> size_of_array. + if (is_array($value) && array_keys($value) != range(0, count($value) - 1)) { + return id(new PhutilJSON())->encodeFormatted($value); + } else { + return json_encode($value); + } + } + } diff --git a/src/applications/config/controller/PhabricatorConfigEditController.php b/src/applications/config/controller/PhabricatorConfigEditController.php index 3960c44408..2145eaf416 100644 --- a/src/applications/config/controller/PhabricatorConfigEditController.php +++ b/src/applications/config/controller/PhabricatorConfigEditController.php @@ -19,6 +19,8 @@ final class PhabricatorConfigEditController return new Aphront404Response(); } + $default = $this->prettyPrintJSON($config[$this->key]); + // Check if the config key is already stored in the database. // Grab the value if it is. $value = null; @@ -72,14 +74,7 @@ final class PhabricatorConfigEditController ->setTitle('You broke everything!') ->setErrors($errors); } else { - // Check not only that it's an array, but that it's an "unnatural" array - // meaning that the keys aren't 0 -> size_of_array. - if (is_array($value) && - array_keys($value) != range(0, count($value) - 1)) { - $value = id(new PhutilJSON())->encodeFormatted($value); - } else { - $value = json_encode($value); - } + $value = $this->prettyPrintJSON($value); } $form @@ -91,11 +86,26 @@ final class PhabricatorConfigEditController ->setValue($value) ->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL) ->setCustomClass('PhabricatorMonospaced') - ->setName('value')) + ->setName('value')) ->appendChild( id(new AphrontFormSubmitControl()) ->addCancelButton($config_entry->getURI()) - ->setValue(pht('Save Config Entry'))); + ->setValue(pht('Save Config Entry'))) + ->appendChild( + phutil_render_tag( + 'p', + array( + 'class' => 'aphront-form-input', + ), + 'If left blank, the setting will return to its default value. '. + 'Its default value is:')) + ->appendChild( + phutil_render_tag( + 'pre', + array( + 'class' => 'aphront-form-input', + ), + phutil_escape_html($default))); $title = pht('Edit %s', $this->key); $short = pht('Edit');