From e80edc445ec191bab1ba8aa5227c1359397ba3dd Mon Sep 17 00:00:00 2001 From: Will Rossiter Date: Sat, 6 Sep 2014 11:22:05 +1200 Subject: [PATCH] Move advanced form out to it's own class Make page title customizable through the Config system (Fixes #44) --- code/controllers/DocumentationViewer.php | 70 ++++++------------- .../forms/DocumentationAdvancedSearchForm.php | 66 +++++++++++++++++ code/models/DocumentationPage.php | 9 +-- templates/DocumentationViewer.ss | 2 +- 4 files changed, 94 insertions(+), 53 deletions(-) create mode 100644 code/forms/DocumentationAdvancedSearchForm.php diff --git a/code/controllers/DocumentationViewer.php b/code/controllers/DocumentationViewer.php index a3bc220..4d9d9af 100755 --- a/code/controllers/DocumentationViewer.php +++ b/code/controllers/DocumentationViewer.php @@ -31,6 +31,11 @@ class DocumentationViewer extends Controller { */ private static $google_analytics_code = ''; + /** + * @var string + */ + private static $documentation_title = 'SilverStripe Documentation'; + /** * @var string */ @@ -399,7 +404,7 @@ class DocumentationViewer extends Controller { 'Link' => $link, 'LinkingMode' => $mode, 'Content' => $content, - + ))); } } @@ -686,7 +691,7 @@ class DocumentationViewer extends Controller { $output = ""; foreach($pages as $page) { - $output = $page->Title .' - '. $output; + $output = $page->Title .' – '. $output; } return $output; @@ -922,60 +927,22 @@ class DocumentationViewer extends Controller { */ public function AdvancedSearchForm() { $entities = DocumentationService::get_registered_entities(); - $versions = array(); - - foreach($entities as $entity) { - $versions[$entity->getFolder()] = $entity->getVersions(); - } - - // get a list of all the unique versions - $uniqueVersions = array_unique(ArrayLib::flatten(array_values($versions))); - asort($uniqueVersions); - $uniqueVersions = array_combine($uniqueVersions,$uniqueVersions); - - $q = ($q = $this->getSearchQuery()) ? $q->NoHTML() : ""; - - // klude to take an array of objects down to a simple map - $entities = new ArrayList($entities); - $entities = $entities->map('Folder', 'Title'); - - // if we haven't gone any search limit then we're searching everything - $searchedEntities = $this->getSearchedEntities(); - if(count($searchedEntities) < 1) $searchedEntities = $entities; - - $searchedVersions = $this->getSearchedVersions(); - if(count($searchedVersions) < 1) $searchedVersions = $uniqueVersions; - $fields = new FieldList( - new TextField('Search', _t('DocumentationViewer.KEYWORDS', 'Keywords'), $q), - new CheckboxSetField('Entities', _t('DocumentationViewer.MODULES', 'Modules'), $entities, $searchedEntities), - new CheckboxSetField('Versions', _t('DocumentationViewer.VERSIONS', 'Versions'), - $uniqueVersions, $searchedVersions - ) - ); - - $actions = new FieldList( - new FormAction('results', _t('DocumentationViewer.SEARCH', 'Search')) - ); - $required = new RequiredFields(array('Search')); - - $form = new Form($this, 'AdvancedSearchForm', $fields, $actions, $required); - $form->disableSecurityToken(); - $form->setFormMethod('GET'); - $form->setFormAction(self::$link_base . 'DocumentationSearchForm'); - - return $form; + return new DocumentationAdvancedSearchForm($this); } /** - * check if the Advanced SearchForm can be displayed - * enabled by default, to disable use: + * Check if the Advanced SearchForm can be displayed. It is enabled by + * default, to disable use: + * + * * DocumentationSearch::enable_advanced_search(false); - * + * + * * @return bool */ public function getAdvancedSearchEnabled() { - return DocumentationSearch::advanced_search_enabled(); + return DocumentationSearch::advanced_search_enabled(); } /** @@ -1094,4 +1061,11 @@ class DocumentationViewer extends Controller { return $code; } } + + /** + * @return string + */ + public function getDocumentationTitle() { + return Config::inst()->get('DocumentationViewer', 'documentation_title'); + } } diff --git a/code/forms/DocumentationAdvancedSearchForm.php b/code/forms/DocumentationAdvancedSearchForm.php new file mode 100644 index 0000000..8371b89 --- /dev/null +++ b/code/forms/DocumentationAdvancedSearchForm.php @@ -0,0 +1,66 @@ +getFolder()] = $entity->getVersions(); + } + + // get a list of all the unique versions + $uniqueVersions = array_unique(ArrayLib::flatten(array_values($versions))); + asort($uniqueVersions); + $uniqueVersions = array_combine($uniqueVersions,$uniqueVersions); + + $q = ($q = $this->getSearchQuery()) ? $q->NoHTML() : ""; + + // klude to take an array of objects down to a simple map + $entities = new ArrayList($entities); + $entities = $entities->map('Folder', 'Title'); + + // if we haven't gone any search limit then we're searching everything + $searchedEntities = $controller->getSearchedEntities(); + + if(count($searchedEntities) < 1) { + $searchedEntities = $entities; + } + + $searchedVersions = $controller->getSearchedVersions(); + + if(count($searchedVersions) < 1) { + $searchedVersions = $uniqueVersions; + } + + $fields = new FieldList( + new TextField('Search', _t('DocumentationViewer.KEYWORDS', 'Keywords'), $q), + new CheckboxSetField('Entities', _t('DocumentationViewer.MODULES', 'Modules'), $entities, $searchedEntities), + new CheckboxSetField('Versions', _t('DocumentationViewer.VERSIONS', 'Versions'), + $uniqueVersions, $searchedVersions + ) + ); + + $actions = new FieldList( + new FormAction('results', _t('DocumentationViewer.SEARCH', 'Search')) + ); + + $required = new RequiredFields(array('Search')); + + parent::__construct( + $controller, + 'AdvancedSearchForm', + $fields, + $actions, + $required + ); + + $this->disableSecurityToken(); + $this->setFormMethod('GET'); + $this->setFormAction(self::$link_base . 'DocumentationSearchForm'); + + } \ No newline at end of file diff --git a/code/models/DocumentationPage.php b/code/models/DocumentationPage.php index 63868d6..c03cb3d 100755 --- a/code/models/DocumentationPage.php +++ b/code/models/DocumentationPage.php @@ -1,10 +1,11 @@ <% base_tag %> - <% if PageTitle %>$PageTitle –<% end_if %>SilverStripe Documentation + <% if PageTitle %>$PageTitle<% end_if %>$DocumentationTitle