Completed
Push — master ( b4d648...ce2a19 )
by Craig
19:25 queued 10:39
created

SearchBlock::getFormOptions()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 11
nc 6
nop 0
dl 0
loc 20
rs 9.2
c 0
b 0
f 0
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');
0 ignored issues
show
Unused Code introduced by
$title is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
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