Skip to content

Commit

Permalink
Merge pull request #12 from PlasticStudio/feature/button_text_config
Browse files Browse the repository at this point in the history
Add configurable submit_button_text
  • Loading branch information
monkeyfeet committed Mar 25, 2021
2 parents 73f1b1d + 6b57344 commit 68818fe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -113,4 +114,5 @@ PlasticStudio\Search\SearchPageController:
Sort: 'DatePublished ASC'
defaults:
sort: 'Title ASC'
submit_button_text: 'Go'
```
13 changes: 11 additions & 2 deletions src/SearchControllerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 68818fe

Please sign in to comment.