From 8ae01fdc6bf620c44ebf0853627fb059881d0b15 Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 22 Feb 2018 12:51:23 -0800 Subject: [PATCH] Fix documentation behaviors for the new proxy functions for custom datasource fields Summary: Ref T13090. The doc string in "any()" wasn't specified correctly and the help page wasn't getting enough supporting data to build properly. Test Plan: Viewed "Reference: Advanced Functions" for a custom datasource field and got more helpful help. Maniphest Tasks: T13090 Differential Revision: https://secure.phabricator.com/D19128 --- ...ricatorTypeaheadFunctionHelpController.php | 20 +++++++++++++++++-- ...orTypeaheadModularDatasourceController.php | 6 ++++++ ...ApplicationSearchAnyFunctionDatasource.php | 2 +- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/applications/typeahead/controller/PhabricatorTypeaheadFunctionHelpController.php b/src/applications/typeahead/controller/PhabricatorTypeaheadFunctionHelpController.php index 3084b2d434..27b30a6278 100644 --- a/src/applications/typeahead/controller/PhabricatorTypeaheadFunctionHelpController.php +++ b/src/applications/typeahead/controller/PhabricatorTypeaheadFunctionHelpController.php @@ -19,9 +19,25 @@ final class PhabricatorTypeaheadFunctionHelpController return new Aphront404Response(); } - $source = $sources[$class]; + $raw_parameters = $request->getStr('parameters'); + if ($raw_parameters) { + $parameters = phutil_json_decode($raw_parameters); + } else { + $parameters = array(); + } + + $source = id(clone $sources[$class]) + ->setParameters($parameters); + + // This can fail for some types of datasources (like the custom field proxy + // datasources) if the "parameters" are wrong. Just fail cleanly instead + // of fataling. + try { + $application_class = $source->getDatasourceApplicationClass(); + } catch (Exception $ex) { + return new Aphront404Response(); + } - $application_class = $source->getDatasourceApplicationClass(); if ($application_class) { $result = id(new PhabricatorApplicationQuery()) ->setViewer($this->getViewer()) diff --git a/src/applications/typeahead/controller/PhabricatorTypeaheadModularDatasourceController.php b/src/applications/typeahead/controller/PhabricatorTypeaheadModularDatasourceController.php index 2f55c26384..e0ba9a763b 100644 --- a/src/applications/typeahead/controller/PhabricatorTypeaheadModularDatasourceController.php +++ b/src/applications/typeahead/controller/PhabricatorTypeaheadModularDatasourceController.php @@ -226,6 +226,12 @@ final class PhabricatorTypeaheadModularDatasourceController if ($source->getAllDatasourceFunctions()) { $reference_uri = '/typeahead/help/'.get_class($source).'/'; + $parameters = $source->getParameters(); + if ($parameters) { + $reference_uri = (string)id(new PhutilURI($reference_uri)) + ->setQueryParam('parameters', phutil_json_encode($parameters)); + } + $reference_link = phutil_tag( 'a', array( diff --git a/src/infrastructure/customfield/datasource/PhabricatorCustomFieldApplicationSearchAnyFunctionDatasource.php b/src/infrastructure/customfield/datasource/PhabricatorCustomFieldApplicationSearchAnyFunctionDatasource.php index 9560620db4..31f189988c 100644 --- a/src/infrastructure/customfield/datasource/PhabricatorCustomFieldApplicationSearchAnyFunctionDatasource.php +++ b/src/infrastructure/customfield/datasource/PhabricatorCustomFieldApplicationSearchAnyFunctionDatasource.php @@ -22,7 +22,7 @@ final class PhabricatorCustomFieldApplicationSearchAnyFunctionDatasource 'summary' => pht('Find results with any value.'), 'description' => pht( "This function includes results which have any value. Use a query ". - "like this to find results with any value:\n\n%s". + "like this to find results with any value:\n\n%s", '> any()'), ), );