|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Zikula package. |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright Zikula Foundation - http://zikula.org/ |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Zikula\SearchModule\Block; |
|
13
|
|
|
|
|
14
|
|
|
use Zikula\BlocksModule\AbstractBlockHandler; |
|
15
|
|
|
use Zikula\SearchModule\AbstractSearchable; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Block to display a search form |
|
19
|
|
|
*/ |
|
20
|
|
|
class SearchBlock extends AbstractBlockHandler |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* display block |
|
24
|
|
|
* |
|
25
|
|
|
* @param array $properties |
|
26
|
|
|
* @return string the rendered bock |
|
27
|
|
|
*/ |
|
28
|
|
|
public function display(array $properties) |
|
29
|
|
|
{ |
|
30
|
|
|
$title = !empty($properties['title']) ? $properties['title'] : ''; |
|
31
|
|
|
if (!$this->hasPermission('Searchblock::', "$title::", ACCESS_READ)) { |
|
32
|
|
|
return ''; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
// set some defaults |
|
36
|
|
|
if (empty($title)) { |
|
37
|
|
|
$title = $this->__('Search'); |
|
|
|
|
|
|
38
|
|
|
} |
|
39
|
|
|
if (!isset($properties['displaySearchBtn'])) { |
|
40
|
|
|
$properties['displaySearchBtn'] = false; |
|
41
|
|
|
} |
|
42
|
|
|
if (!isset($properties['active'])) { |
|
43
|
|
|
$properties['active'] = []; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
$templateParameters = [ |
|
47
|
|
|
'properties' => $properties, |
|
48
|
|
|
'pluginOptions' => [] |
|
49
|
|
|
]; |
|
50
|
|
|
|
|
51
|
|
|
return $this->renderView('@ZikulaSearchModule/Block/search.html.twig', $templateParameters); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Returns the fully qualified class name of the block's form class. |
|
56
|
|
|
* |
|
57
|
|
|
* @return string Template path |
|
58
|
|
|
*/ |
|
59
|
|
|
public function getFormClassName() |
|
60
|
|
|
{ |
|
61
|
|
|
return 'Zikula\SearchModule\Block\Form\Type\SearchBlockType'; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Returns any array of form options. |
|
66
|
|
|
* |
|
67
|
|
|
* @return array Options array |
|
68
|
|
|
*/ |
|
69
|
|
|
public function getFormOptions() |
|
70
|
|
|
{ |
|
71
|
|
|
$searchModules = []; |
|
72
|
|
|
$searchableModules = $this->get('zikula_search_module.internal.searchable_module_collector')->getAll(); |
|
73
|
|
|
foreach (array_keys($searchableModules) as $moduleName) { |
|
74
|
|
|
$displayName = $this->get('kernel')->getModule($moduleName)->getMetaData()->getDisplayName(); |
|
75
|
|
|
$searchModules[$displayName] = $moduleName; |
|
76
|
|
|
} |
|
77
|
|
|
// remove disabled |
|
78
|
|
|
foreach ($searchModules as $displayName => $moduleName) { |
|
79
|
|
|
if ((bool) $this->getVar('disable_' . $moduleName, true)) { |
|
80
|
|
|
unset($searchModules[$displayName]); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
// get all the search plugins |
|
85
|
|
|
return [ |
|
86
|
|
|
'activeModules' => $searchModules |
|
87
|
|
|
]; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Returns the template used for rendering the editing form. |
|
92
|
|
|
* |
|
93
|
|
|
* @return string Template path |
|
94
|
|
|
*/ |
|
95
|
|
|
public function getFormTemplate() |
|
96
|
|
|
{ |
|
97
|
|
|
return '@ZikulaSearchModule/Block/search_modify.html.twig'; |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.