From 410312c6414eef69f32fdabafdfc3ebbd3e3e032 Mon Sep 17 00:00:00 2001 From: Cam Findlay Date: Wed, 17 Dec 2014 09:30:17 +1300 Subject: [PATCH] Pass the current version to the search From a UX POV, when I'm searching docs I'm likely to be working on a site of a specific version - results of docs from older or newer versions are likely to be less relevant to me. If I want to search wider after my initial search I can use the check boxes on the advanced search. --- code/forms/DocumentationSearchForm.php | 27 ++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/code/forms/DocumentationSearchForm.php b/code/forms/DocumentationSearchForm.php index a08d705..17c1241 100644 --- a/code/forms/DocumentationSearchForm.php +++ b/code/forms/DocumentationSearchForm.php @@ -3,18 +3,25 @@ class DocumentationSearchForm extends Form { public function __construct($controller) { - $versions = HiddenField::create( - 'Versions', - _t('DocumentationViewer.VERSIONS', 'Versions'), - implode(',', $controller->getManifest()->getAllVersions()) - ); + $fields = new FieldList( TextField::create('q', _t('DocumentationViewer.SEARCH', 'Search'), '') - ->setAttribute('placeholder', _t('DocumentationViewer.SEARCH', 'Search')), - $versions + ->setAttribute('placeholder', _t('DocumentationViewer.SEARCH', 'Search')) ); - + + $page = $controller->getPage(); + + if($page){ + $versions = HiddenField::create( + 'Versions', + _t('DocumentationViewer.VERSIONS', 'Versions'), + $page->getEntity()->getVersion() + ); + + $fields->push($versions); + } + $actions = new FieldList( new FormAction('results', _t('DocumentationViewer.SEARCH', 'Search')) ); @@ -24,7 +31,7 @@ class DocumentationSearchForm extends Form { $this->disableSecurityToken(); $this->setFormMethod('GET'); $this->setFormAction($controller->Link('results')); - + $this->addExtraClass('search'); } -} \ No newline at end of file +}