Completed
Push — develop ( 41c7f2...c75883 )
by
unknown
08:12
created

TextSearchForm::setHeadscripts()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @license MIT
7
 * @copyright  2013 - 2016 Cross Solution <http://cross-solution.de>
8
 */
9
  
10
/** */
11
namespace Core\Form;
12
13
use string;
14
use Zend\Form\Form as ZfForm;
15
16
/**
17
 * ${CARET}
18
 * 
19
 * @author Mathias Gelhausen <[email protected]>
20
 * @todo write test 
21
 */
22
class TextSearchForm extends ZfForm implements HeadscriptProviderInterface
23
{
24
    protected $headscripts = [
25
        'Core/js/core.searchform.js'
26
    ];
27
28
    protected $options = [
29
        'button_element' => 'text',
30
        'placeholder'    => /* @translate */ 'Search query',
31
    ];
32
33
    /**
34
     * Sets the array of script names.
35
     *
36
     * @param string[] $scripts
37
     *
38
     * @return self
39
     */
40
    public function setHeadscripts(array $scripts)
41
    {
42
        $this->headscripts = $scripts;
43
44
        return $this;
45
    }
46
47
    /**
48
     * Gets the array of script names.
49
     *
50
     * @return string[]
51
     */
52
    public function getHeadscripts()
53
    {
54
        return $this->headscripts;
55
    }
56
57
    public function setSearchParams($params)
58
    {
59
        $json = \Zend\Json\Json::encode($params);
60
        $this->setAttribute('data-search-params', $json);
61
62
        return $this;
63
    }
64
65
    public function init()
66
    {
67
        $this->setName('search');
68
        $this->setAttributes([
69
                                 'data-handle-by' => 'native',
70
                                 'method' => 'get',
71
                                 'class' => 'form-inline search-form',
72
                             ]);
73
74
        $this->add([
75
                       'type' => 'Text',
76
                       'name' => 'text',
77
                       'options' => [
78
                           'label' => /*@translate*/ 'Search',
79
                           'use_formrow_helper' => false,
80
                       ],
81
                       'attributes' => [
82
                           'class' => 'form-control',
83
                           'placeholder' => $this->getOption('placeholder'),
84
                       ]
85
                   ]);
86
87
88
    }
89
}