Completed
Push — develop ( 7d6075...b57d28 )
by
unknown
15:48 queued 07:06
created

TextSearchFormButtonsFieldset::setSpan()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
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 Zend\Form\Element;
14
use Zend\Form\Exception;
15
use Zend\Form\Fieldset;
16
use Zend\Form\FieldsetInterface;
17
18
/**
19
 * Fieldset for the buttons of a TextSearchForm
20
 *
21
 * @author Mathias Gelhausen <[email protected]>
22
 * @since  0.25
23
 */
24
class TextSearchFormButtonsFieldset extends Fieldset
25
{
26
    public function init()
27
    {
28
        $this->addDefaultButtons();
29
    }
30
31
    /**
32
     * Adds the default buttons.
33
     *
34
     */
35
    protected function addDefaultButtons()
36
    {
37
        $this->addButton( /*@translate*/ 'Search', -1000, 'submit'
38
        );
39
        $this->addButton( /*@translate*/ 'Clear', -1100, 'reset'
40
        );
41
    }
42
43
44
    /**
45
     * Adds a button
46
     *
47
     * @param string $label
48
     * @param int    $priority
49
     * @param string $type
50
     *
51
     * @return Fieldset|FieldsetInterface
52
     */
53
    public function addButton($label, $priority = 0, $type = "button")
54
    {
55
        if (is_array($label)) {
56
            $name  = $label[0];
57
            $label = $label[1];
58
        } else {
59
            $name = strtolower(str_replace(' ', '_', $label));
60
        }
61
62
        $spec = [
63
            'type'       => 'Button',
64
            'name'       => $name,
65
            'options'    => [
66
                'label' => $label,
67
            ],
68
            'attributes' => [
69
                'class' => 'btn btn-' . ('submit' == $type ? 'primary' : 'default'),
70
                'type'  => $type,
71
            ],
72
        ];
73
74
75
        return $this->add($spec, ['priority' => $priority]);
76
    }
77
78
    /**
79
     * Sets the column span of the button group.
80
     *
81
     * Only used, if the buttons aren't rendered on an element.
82
     *
83
     * @param int $span
84
     *
85
     * @return self
86
     */
87
    public function setSpan($span)
88
    {
89
        $this->setOption('span', $span);
90
91
        return $this;
92
    }
93
94
    /**
95
     * Gets the column span of the button group.
96
     *
97
     * @return int
98
     */
99
    public function getSpan()
100
    {
101
        return $this->getOption('span') ? : 12;
102
    }
103
}