silverstripe /
silverstripe-fulltextsearch
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace SilverStripe\FullTextSearch\Solr\Control; |
||||
| 4 | |||||
| 5 | use SilverStripe\Control\HTTPRequest; |
||||
| 6 | use SilverStripe\Core\Extension; |
||||
| 7 | use SilverStripe\Forms\FieldList; |
||||
| 8 | use SilverStripe\Forms\FormAction; |
||||
| 9 | use SilverStripe\Forms\TextField; |
||||
| 10 | use SilverStripe\FullTextSearch\Solr\Forms\SearchForm; |
||||
| 11 | use SilverStripe\ORM\FieldType\DBField; |
||||
| 12 | |||||
| 13 | class ContentControllerExtension extends Extension |
||||
| 14 | { |
||||
| 15 | private static $allowed_actions = array( |
||||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||||
| 16 | 'SearchForm', |
||||
| 17 | 'results', |
||||
| 18 | ); |
||||
| 19 | |||||
| 20 | /** |
||||
| 21 | * Site search form |
||||
| 22 | * |
||||
| 23 | * @return SearchForm |
||||
| 24 | */ |
||||
| 25 | public function SearchForm() |
||||
| 26 | { |
||||
| 27 | $searchText = _t('SilverStripe\\CMS\\Search\\SearchForm.SEARCH', 'Search'); |
||||
| 28 | /** @var HTTPRequest $currentRequest */ |
||||
| 29 | $currentRequest = $this->owner->getRequest(); |
||||
| 30 | |||||
| 31 | if ($currentRequest && $currentRequest->getVar('Search')) { |
||||
| 32 | $searchText = $currentRequest->getVar('Search'); |
||||
| 33 | } |
||||
| 34 | |||||
| 35 | $fields = FieldList::create( |
||||
| 36 | TextField::create('Search', false, $searchText) |
||||
| 37 | ); |
||||
| 38 | $actions = FieldList::create( |
||||
| 39 | FormAction::create('results', _t('SilverStripe\\CMS\\Search\\SearchForm.GO', 'Go')) |
||||
| 40 | ); |
||||
| 41 | return SearchForm::create($this->owner, 'SearchForm', $fields, $actions); |
||||
| 42 | } |
||||
| 43 | |||||
| 44 | /** |
||||
| 45 | * Process and render search results. |
||||
| 46 | * |
||||
| 47 | * @param array $data The raw request data submitted by user |
||||
| 48 | * @param SearchForm $form The form instance that was submitted |
||||
| 49 | * @param HTTPRequest $request Request generated for this action |
||||
| 50 | */ |
||||
| 51 | public function results($data, $form, $request) |
||||
|
0 ignored issues
–
show
The parameter
$request is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. Loading history...
|
|||||
| 52 | { |
||||
| 53 | $data = [ |
||||
| 54 | 'Results' => $form->getResults(), |
||||
| 55 | 'Query' => DBField::create_field('Text', $form->getSearchQuery()), |
||||
| 56 | 'Title' => _t('SilverStripe\\CMS\\Search\\SearchForm.SearchResults', 'Search Results') |
||||
| 57 | ]; |
||||
| 58 | return $this->owner->customise($data)->renderWith(['Page_results_solr', 'Page_results', 'Page']); |
||||
| 59 | } |
||||
| 60 | } |
||||
| 61 |