1 | <?php |
||||||
2 | |||||||
3 | namespace LeKoala\SimpleSearch; |
||||||
4 | |||||||
5 | use SilverStripe\Forms\Form; |
||||||
6 | use SilverStripe\Core\Extension; |
||||||
7 | use SilverStripe\Forms\FieldList; |
||||||
8 | use SilverStripe\Forms\TextField; |
||||||
9 | use SilverStripe\Forms\FormAction; |
||||||
10 | use SilverStripe\Control\Director; |
||||||
11 | use SilverStripe\Core\Config\Config; |
||||||
12 | use SilverStripe\ErrorPage\ErrorPage; |
||||||
0 ignored issues
–
show
|
|||||||
13 | |||||||
14 | /** |
||||||
15 | * A simple alternative to full text search |
||||||
16 | * |
||||||
17 | * @property \PageController|\LeKoala\SimpleSearch\SimpleSearchControllerExtension $owner |
||||||
18 | */ |
||||||
19 | class SimpleSearchControllerExtension extends Extension |
||||||
20 | { |
||||||
21 | private static $allowed_actions = [ |
||||||
0 ignored issues
–
show
|
|||||||
22 | 'SimpleSearchForm', |
||||||
23 | ]; |
||||||
24 | |||||||
25 | /** |
||||||
26 | * Simple site search form |
||||||
27 | * |
||||||
28 | * @return Form |
||||||
29 | */ |
||||||
30 | public function SimpleSearchForm() |
||||||
31 | { |
||||||
32 | $placeholder = _t('SimpleSearch.SEARCH', 'Search'); |
||||||
33 | $searchText = ''; |
||||||
34 | $request = $this->owner->getRequest(); |
||||||
0 ignored issues
–
show
The method
getRequest() does not exist on LeKoala\SimpleSearch\Sim...archControllerExtension .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||||
35 | if ($request) { |
||||||
36 | $searchText = $request->getVar('q'); |
||||||
37 | } |
||||||
38 | $fieldsList = []; |
||||||
39 | |||||||
40 | $Search = new TextField('q', false, $searchText); |
||||||
0 ignored issues
–
show
false of type false is incompatible with the type null|string expected by parameter $title of SilverStripe\Forms\TextField::__construct() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
41 | $Search->setAttribute('placeholder', $placeholder); |
||||||
42 | $fieldsList[] = $Search; |
||||||
43 | |||||||
44 | $fields = new FieldList($fieldsList); |
||||||
45 | |||||||
46 | $actionsList = []; |
||||||
47 | |||||||
48 | $Go = new FormAction('doSearch', _t('SimpleSearch.GO', 'Go')); |
||||||
49 | $Go->setName(''); |
||||||
50 | $Go->setUseButtonTag(true); |
||||||
51 | $Go->setButtonContent('<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M10,18c1.846,0,3.543-0.635,4.897-1.688l4.396,4.396l1.414-1.414l-4.396-4.396C17.365,13.543,18,11.846,18,10 c0-4.411-3.589-8-8-8s-8,3.589-8,8S5.589,18,10,18z M10,4c3.309,0,6,2.691,6,6s-2.691,6-6,6s-6-2.691-6-6S6.691,4,10,4z"/></svg>'); |
||||||
52 | $actionsList[] = $Go; |
||||||
53 | |||||||
54 | $actions = new FieldList($actionsList); |
||||||
55 | |||||||
56 | // Create a simple search form |
||||||
57 | $searchControllerLink = $this->SearchControllerLink(); |
||||||
58 | $form = Form::create($this->owner, __FUNCTION__, $fields, $actions); |
||||||
59 | $form->setFormMethod('GET'); |
||||||
60 | $form->setFormAction($searchControllerLink); |
||||||
61 | $form->disableSecurityToken(); |
||||||
62 | |||||||
63 | return $form; |
||||||
64 | } |
||||||
65 | |||||||
66 | /** |
||||||
67 | * @return string |
||||||
68 | */ |
||||||
69 | public function SearchControllerLink() |
||||||
70 | { |
||||||
71 | $directorRules = Config::inst()->get(Director::class, 'rules'); |
||||||
72 | $searchControllerLink = '/search/'; |
||||||
73 | foreach ($directorRules as $segment => $controller) { |
||||||
74 | if ($controller == SearchController::class) { |
||||||
0 ignored issues
–
show
The type
LeKoala\SimpleSearch\SearchController was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||||||
75 | $searchControllerLink = '/' . $segment . '/'; |
||||||
76 | } |
||||||
77 | } |
||||||
78 | return $searchControllerLink; |
||||||
79 | } |
||||||
80 | } |
||||||
81 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths