1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Nip\Form\Renderer\AbstractRenderer; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class Nip_Form_Renderer_Button_Abstract |
7
|
|
|
*/ |
8
|
|
|
abstract class Nip_Form_Renderer_Button_Abstract |
|
|
|
|
9
|
|
|
{ |
10
|
|
|
protected $_renderer; |
11
|
|
|
|
12
|
|
|
protected $_button; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @param AbstractRenderer $renderer |
16
|
|
|
* @return $this |
17
|
|
|
*/ |
18
|
|
|
public function setRenderer(AbstractRenderer $renderer) |
19
|
|
|
{ |
20
|
|
|
$this->_renderer = $renderer; |
21
|
|
|
|
22
|
|
|
return $this; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @return AbstractRenderer |
27
|
|
|
*/ |
28
|
|
|
public function getRenderer() |
29
|
|
|
{ |
30
|
|
|
return $this->_renderer; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param Nip_Form_Button_Abstract $item |
35
|
|
|
* @return $this |
36
|
|
|
*/ |
37
|
|
|
public function setItem(Nip_Form_Button_Abstract $item) |
38
|
|
|
{ |
39
|
|
|
$this->_item = $item; |
|
|
|
|
40
|
|
|
|
41
|
|
|
return $this; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return Nip_Form_Button_Abstract |
46
|
|
|
*/ |
47
|
|
|
public function getItem() |
48
|
|
|
{ |
49
|
|
|
return $this->_item; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
|
53
|
|
|
public function render() |
54
|
|
|
{ |
55
|
|
|
$return = ''; |
56
|
|
|
$return .= $this->renderItem(); |
|
|
|
|
57
|
|
|
|
58
|
|
|
return $return; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function renderItem() |
62
|
|
|
{ |
63
|
|
|
$return = $this->generateItem(); |
|
|
|
|
64
|
|
|
|
65
|
|
|
return $return; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function generateItem() |
69
|
|
|
{ |
70
|
|
|
return; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function renderAttributes($overrides = []) |
74
|
|
|
{ |
75
|
|
|
$attribs = $this->getItem()->getAttribs(); |
76
|
|
|
if (!isset($attribs['title'])) { |
77
|
|
|
$attribs['title'] = $this->getItem()->getLabel(); |
78
|
|
|
} |
79
|
|
|
$itemAttribs = $this->getItemAttribs(); |
80
|
|
|
$return = ''; |
81
|
|
|
foreach ($attribs as $name => $value) { |
82
|
|
|
if (in_array($name, $itemAttribs)) { |
83
|
|
|
if (in_array($name, array_keys($overrides))) { |
84
|
|
|
$value = $overrides[$name]; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
$return .= ' '.$name.'="'.$value.'"'; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
return $return; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @return array |
96
|
|
|
*/ |
97
|
|
|
public function getItemAttribs() |
98
|
|
|
{ |
99
|
|
|
return ['id', 'name', 'style', 'class', 'title', 'read_only', 'disabled']; |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.