From 6b57344227a0055e4ff7c3124f22273e9ce756ff Mon Sep 17 00:00:00 2001 From: psdigital Date: Thu, 25 Mar 2021 16:29:30 +1300 Subject: [PATCH] Add configurable submit_button_text --- README.md | 2 ++ src/SearchControllerExtension.php | 13 +++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1acfc8c..46167cf 100755 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ The built-in SilverStripe search form is a very simple search engine. This plugi * `Label`: front-end field label * `Sort`: SQL sort string * `defaults`: Default attributes or settings, as opposed to those submitted through the search form (currently only configured to use `sort`). +* `submit_button_text`: Text to use on search form submit button (defaults to "Search") # Example configuration @@ -113,4 +114,5 @@ PlasticStudio\Search\SearchPageController: Sort: 'DatePublished ASC' defaults: sort: 'Title ASC' + submit_button_text: 'Go' ``` diff --git a/src/SearchControllerExtension.php b/src/SearchControllerExtension.php index bbb8435..331cfdc 100755 --- a/src/SearchControllerExtension.php +++ b/src/SearchControllerExtension.php @@ -13,6 +13,7 @@ use SilverStripe\Forms\DropdownField; use SilverStripe\Forms\HiddenField; use SilverStripe\View\Requirements; +use SilverStripe\Core\Config\Config; class SearchControllerExtension extends DataExtension { @@ -36,8 +37,12 @@ public function SearchForm(){ $fields->push( TextField::create('query','',SearchPageController::get_query())->addExtraClass('query')->setAttribute('placeholder', 'Keywords') ); // create the form actions (we only need a submit button) + $submit_button_text = 'Search'; + if (Config::inst()->get('PlasticStudio\Search\SearchPageController', 'submit_button_text')) { + $submit_button_text = Config::inst()->get('PlasticStudio\Search\SearchPageController', 'submit_button_text'); + } $actions = FieldList::create( - FormAction::create("doSearchForm")->setTitle("Search") + FormAction::create("doSearchForm")->setTitle($submit_button_text) ); // now build the actual form object @@ -169,8 +174,12 @@ public function AdvancedSearchForm(){ } // create the form actions (we only need a submit button) + $submit_button_text = 'Search'; + if (Config::inst()->get('PlasticStudio\Search\SearchPageController', 'submit_button_text')) { + $submit_button_text = Config::inst()->get('PlasticStudio\Search\SearchPageController', 'submit_button_text'); + } $actions = FieldList::create( - FormAction::create("doSearchForm")->setTitle("Search") + FormAction::create("doSearchForm")->setTitle($submit_button_text) ); // now build the actual form object